Cannot read property 'clearValidate' of undefined

版权声明:本文为QQ帝国原创博客,转载请附上链接,谢谢。 https://blog.csdn.net/QQ_Empire/article/details/89356135

这个错误是因为你的dom元素还没有加载完,你就想使用resetFields置空。也就是你写的this.$refs['addForm'].resetFields();这个里面的addForm还没有加载出来呢。

解决:nextTick() 

Vue.nextTick用于延迟执行一段代码

详细讲解:https://www.jianshu.com/p/a7550c0e164f

this.$nextTick(()=>{

   this.$refs['addForm'].clearValidate();

})


 

猜你喜欢

转载自blog.csdn.net/QQ_Empire/article/details/89356135