2.3.3
Chrome 64.0.3282.186
2.5.16
https://jsfiddle.net/s5ar1un3/39/
期望resetFields
把formData.text
还原为初始值。
resetFields
把formData.text
还原为formData.value
的初始值。
Translation of this issue:
Element UI version
2.3.3
OS/Browsers version
Chrome 64.0.3282.186
Vue version
2.5.16
Reproduction Link
https://jsfiddle.net/s5ar1un3/39/
Steps to reproduce
closed mode frame
click the 'point me' button again and make a mistake.
What is Expected?
Expect resetFields
to restore formData.text
to its initial value.
What is actually happening?
resetFields
reduced formData.text
to the initial value of formData.value
.
form.vue
created() {
this.$on('el.form.addField', (field) => {
if (field) {
this.fields.push(field);
}
}
this.$on('el.form.removeField', (field) => {
if (field.prop) {
this.fields.splice(this.fields.indexOf(field), 1);
}
});
}
resetFields() {
...
this.fields.forEach(field => {
field.resetField();
});
},
form-item.vue
mounted() {
if (this.prop) {
this.dispatch('ElForm', 'el.form.addField', [this]);
...
let initialValue = this.fieldValue;
...
Object.defineProperty(this, 'initialValue', {
value: initialValue
});
...
}
}
resetField() {
this.validateDisabled = true;
if (Array.isArray(value)) {
prop.o[prop.k] = [].concat(this.initialValue);
} else {
prop.o[prop.k] = this.initialValue;
}
}
v-if/v-else
时,由于数据变动,vue
比较差异更新,组件已经变新的了,然鹅this.initialValue
是旧组件值,所以resetFields
后数据就是串的。v-if
,但是mounted
阶段这两个组件是不满足if(this.prop)
的,意思就是就算排除initialValue
的问题,重置的也只会是一个组件。You need to key
the form items: https://jsfiddle.net/s5ar1un3/41/
和 if(this.prop)
无关,是因为切换 formData.class
时触发了其他 <el-form-item>
的 beforeDestroy
钩子。可以在切换 formData.class
后重置表单:https://jsfiddle.net/s5ar1un3/42/
嗯嗯 发现了 所以撤销了后面的commit 谢谢你
Most helpful comment
You need to
key
the form items: https://jsfiddle.net/s5ar1un3/41/