重置表单出错:Cannot read property 'resetFields' of undefined,表单是动态创建的,比如:
<el-dialog :title="dialogOption.title + dialogOption.block" v-model="dialogOption.visible" size="tiny">
<el-form ref="formModel" :model="formModel" :rules="rules" label-width="90px">
<dynamic-form :formModel="formModel" :formFields="formFields" :sources="sources" :rules="rules"></dynamic-form>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click.native="handleCancel">取 消</el-button>
<el-button type="primary" @click.native="submitForm">确 定</el-button>
</span>
</el-dialog>
刚才又DEGUB了一下,el-dialog组件中动态创建表单元素,如果dialog没有visible出来,

如果dialog先visible出来,就没有问题,如图:

请给 demo。
Demo地址:http://jsfiddle.net/yd5gc123/
点击按钮后,控制台直接报错,Dialog不能弹出。

Demo 似乎不太对?Dialog 能弹出,并且代码里没调用 resetFields
@Leopoldthecoder Demo被篡改了?
改不了的吧。重新写一个吧。
是的,我也有这个问题,setTimeout里resetFields一下就没问题,上来直接resetFields就会提示 resetFields not defined.
这个 issue 先关掉了。如果能够提供在线 demo,可以再打开。
@Leopoldthecoder
如果 dialog 没有 visible出来的时候不可以调用 resetFields吗?
我这边写了个Demo 在点击按钮2 之前 按钮1 会报Cannot read property 'resetFields' of undefined
@U2Fsd
this.$nextTick(()=>{
this.$refs.ruleForm.resetFields();
});
Most helpful comment
@U2Fsd
this.$nextTick(()=>{ this.$refs.ruleForm.resetFields(); });