鍍金池/ 問答/HTML5  Java  HTML/ 使用ElementUI報錯 Expected Object, got Strin

使用ElementUI報錯 Expected Object, got String

1.正在學(xué)習(xí)vue2遇見一個問題 執(zhí)行過程是在Table中選擇一列點擊編輯然后彈出模態(tài)框,把該列內(nèi)容放進模態(tài)框中,但是報錯:[Vue warn]: Invalid prop: type check failed for prop "model". Expected Object, got String.請大家?guī)兔纯?br>DBTable.vue

<template>
<!--...... -->
<!--...... -->
   <el-table-column label="Operation" 
                    width="120">
           <template scope="scope">
              <el-button @click="editItem(scope.$index, tableData)" type="text" size="large">編輯</el-button>
           </template>
   </el-table-column>
<!--...... -->
<!--DBTable.vue 下最后引用模態(tài)框這個組件 -->
    <db-modal :dialogFormVisible="dialogFormVisible" :form="form" v-on:canclemodal="dialogVisible">
    </db-modal>
</template>

<script>
export default {
        data(){
            return {
                tableData: [],
                apiUrl: 'http://127.0.0.1:8081/api/persons',
                sex: '',
                email: '', 
                dialogFormVisible: false,
                form: '',
            }
        },
        components: {
            DbModal
        },
</script>

然后點擊編輯

            editItem: function (index, rows) {
                this.dialogFormVisible = true;
                const itemId = rows[index].id;
                const idurl = 'http://127.0.0.1:8081/api/persons/detail/' + itemId;
                this.$axios.get(idurl).then((response) => {
                    this.form = response.data.extend.person; //返回的數(shù)據(jù)給form
                    console.log(typeof this.form);
                }).catch(function (response) {
                    console.log(response)
                });
            },

附加上DBModal.vue 代碼

<template>
    <el-dialog title="Edit" v-model="dialogFormVisible" :close-on-click-modal="false" :show-close="false">
        <el-form :model="form">
            <el-form-item label="item_id" :label-width="formLabelWidth">
                <el-input :disabled="true" v-model="form.id" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="username" :label-width="formLabelWidth">
                <el-input :disabled="true" v-model="form.username" auto-complete="off"></el-input>
            </el-form-item>

            <el-form-item label="email" :label-width="formLabelWidth">
                <el-input :disabled="true" v-model="form.email" auto-complete="off"></el-input>
            </el-form-item>

            <el-form-item label="phone" :label-width="formLabelWidth">
                <el-input v-model="form.phone" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="sex" :label-width="formLabelWidth">
                <el-input :disabled="true" v-model="form.sex" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="zone" :label-width="formLabelWidth">
                <el-input v-model="form.zone" auto-complete="off"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button :plain="true" type="danger" v-on:click="canclemodal">Cancel</el-button>
            <el-button :plain="true" @click="updateForm(form)">Save</el-button>
        </div>
    </el-dialog>
</template>


<script>
    export default {
        data(){
            return {
                formLabelWidth: '120px',
            }
        },
        props:['dialogFormVisible', 'form'],
        // props: {
        //     dialogFormVisible:'',
        //     form: {
        //         type:[String, Object]
        //     },
        // }, 
        props:{
            dialogFormVisible:'',
            form:{
                type:[Object,String]
            }
        },
        methods: {
            updateForm: function (formName) {
                let itemId = formName.id;
                let phone = formName.phone;
                let zone = formName.zone;
                this.$axios.put('http://127.0.0.1:8081/api/persons/detail/' + itemId, {
                    phone: phone,
                    zone: zone
                })
                    .then(function (response) {
                        console.log(response);
                        this.form = response.data;

                    })
                    .catch(function (error) {
                        console.log(error);
                    });
                location.reload();
            },
            canclemodal: function () {
                this.$emit('canclemodal');
            }
        }

    }

</script>

用了些方法 但是不太好使還是報那個錯誤,請前端大神幫忙看看

回答
編輯回答
安于心

Hotmail signup guide, register for Hotmail for everyone.
http://hotmailentrarlogin.org

2017年12月22日 20:11
編輯回答
挽青絲

Thank your site! information your share is useful to me!
http://howtoget.wiki/

2017年10月10日 22:44
編輯回答
筱饞貓

vue 提醒你應(yīng)該傳一個string而不是現(xiàn)在的boolean
DBModal組件里面定義dialogFormVisible是string,在父組件引用的時候傳的是false布爾型。

2018年7月18日 22:54