element-ui form表单中的form通过计算属性无法设置值

element-ui form表单中的form通过计算属性无法设置值

<template>

<el-form ref="form" :model="form" label-width="80px">

{{JSON.stringify(form)}}

<el-form-item label="活动名称" prop="name"><el-input v-model="form.name"></el-input></el-form-item>

<el-form-item label="活动形式" prop="desc"><el-input type="textarea" v-model="form.desc"></el-input></el-form-item>

<el-form-item>

<el-button type="primary" @click="onSubmit">立即创建</el-button>

<el-button @click="resetForm('form')">重置</el-button>

</el-form-item>

</el-form>

</template>

<script>

export default {

name: 'test-form',

data() {

return {

items: [

{

name: 'name',

value: ''

},

{

name: 'desc',

value: 'desc'

}

],

};

},

computed: {

form:{

set() {},

get () {

let form = {};

for (let index in this.items) {

const key = this.items[index];

form = Object.assign({}, form, {

[key.name]: key.value

});

}

return form;

}

}

},

created() {

setTimeout( () => {

this.$set(this.form,'name','name')

},3000)

},

methods: {

onSubmit() {

console.log('submit!');

},

resetForm(formName) {

this.$refs[formName].resetFields();

}

}

};

</script>

以上是 element-ui form表单中的form通过计算属性无法设置值 的全部内容, 来源链接: utcz.com/p/935843.html

回到顶部