问题描述: 使用element开发我的后台系统,编辑和新增使用了同一个弹出框<el-dialog><el-form></el-form></el-dialog>

绑定了数据data里的commentForm对象

为了在新增弹出框清空表单, 使用了this.$refs[formName].resetFields()

每次第一次点击新增显示弹出框,都会报错

"[Vue warn]: Error in event handler for "click": "TypeError: Cannot read property 'resetFields' of undefined""

问题原因: mouted加载table数据以后,隐藏的弹出框并没有编译渲染进dom里面。

所以@click="dialogFormVisible = true;resetForm('dlgForm')"click弹出的时候$refs并没有获取到dom元素导致 'resetFields' of undefined

解决方法:

1、($nextTick dom下一次更新之后)

            resetForm(formName) {
this.$nextTick(()=>{
this.$refs[formName].resetFields();
})
},

2、(如果是第一次就点击新增就没必要reset, 根据元素undefined判断)

                if (this.$refs[formName] !== undefined) {
this.$refs[formName].resetFields();
}

注意事项:对DOM一系列的js操作最好都要放进Vue.nextTick()的回调函数中

Cannot read property 'resetFields' of undefined 问题及引申的更多相关文章

  1. Vue+elementUI开发中 Cannot read property 'resetFields' of undefined 问题解决以及原因分析

    本人开发的系统中有个添加数据与编辑数据的功能.为了减少代码量,两者使用了同一个dialog,通过不同按钮点击使用对应的方案进行显示. 对了方便,本人在添加数据的按钮的click事件中直接写入了rese ...

  2. element ui 中的 resetFields() 报错'resetFields' of undefined

    每次做各种form表单时,首先要注意的是初始化,但是刚开始若没有仔细看文档,则会自己写个方法将数据设置为空,但是这样就会出现一个问题,表单内存在各种验证,假如是一个弹框内有form表单,弹框出现就执行 ...

  3. Vue-element 的 resetFields of undefined报错

    触发场景:添加表单弹框,当我信息保存成功后会报 [Vue warn]: Error in event handler for "click": "TypeError: C ...

  4. easyui Datagrid查询报错Uncaught TypeError:Cannot read property 'length' of undefined

    1.问题描述 easyui中datagrid执行loadData方法出现如下异常:Cannot read property 'length' of undefined 2.一开始怀疑是js或者页面的问 ...

  5. vue.common.js?e881:433 TypeError: Cannot read property 'nodeName' of undefined

    我觉得吧,是这么个原因,就是响应式要找这个node改它的内容,没找着,就报错了. 用computed监控vuex的state属性,绑定到页面上,如果这个属性改了,因为响应式,那么就要更改页面,如果页面 ...

  6. Uncaught TypeError: Cannot read property 'msie' of undefined

    因为图方便,抄了别人写的一个jquerry插件,运行时“var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ...

  7. SharePoint 2013 Error - TypeError: Unable to get property 'replace' of undefined or null reference

    错误信息 TypeError: Unable to get property ‘replace’ of undefined or null referenceTypeError: Unable to ...

  8. jquery错误: Cannot read property ‘msie’ of undefined

    背景 Web application, 引用了jquery 1.10.2和fancybox 1.3.4 现象 访问页面遭遇Cannot read property ‘msie’ of undefine ...

  9. easyui使用时出现这个Uncaught TypeError: Cannot read property 'combo' of undefined

    easyui使用时出现这个Uncaught TypeError: Cannot read property 'nodeName' of undefined 最后检查发现是必须给select一个id,光 ...

随机推荐

  1. Eclipse_安装SAP_HANA数据库插件

    1.对于Eclipse Oxygen,请添加URL https://tools.hana.ondemand.com/oxygen 2.对于Eclipse luna,请添加URL     https:/ ...

  2. Java8新特性(三)——Optional类、接口方法与新时间日期API

    一.Optional容器类 这是一个可以为null的容器对象.如果值存在则isPresent()方法会返回true,调用get()方法会返回该对象. 查看结构图可以看到有如下常用方法: of(T)—— ...

  3. Android面试收集录 蓝牙与WiFi

    1.打开手机中的蓝牙功能有哪些方法? 法1:使用Intent  ==>new Intent(BluetoothAdaper.ACTION_REQUEST_ENABLE); startActivi ...

  4. P3527 [POI2011]MET-Meteors

    P3527 [POI2011]MET-Meteors 链接 整体二分! 代码 #include<bits/stdc++.h> using namespace std; typedef lo ...

  5. allegro导入网表过程中出现的错误信息

    1. 找不到焊盘PAD,下面这句话的意思是器件封装找不到焊盘46.pad WARNING(SPMHNI-): Unable to load symbol ): Could not find padst ...

  6. es6中类的注意事项

    class Circle { constructor(radius) { this.radius = radius; Circle.circlesMade++; }; static draw(circ ...

  7. LR创建数据源读取excel

    1 在window上创建数据源   2 创建对应的数据文件 excel 注:注意格式和底部的表单名称 3 Vegen中创建参数 注意:机器数据源选择windows的ODBC数据源 SQL查的是(she ...

  8. GraphSAGE 代码解析(三) - aggregators.py

    原创文章-转载请注明出处哦.其他部分内容参见以下链接- GraphSAGE 代码解析(一) - unsupervised_train.py GraphSAGE 代码解析(二) - layers.py ...

  9. git instaweb 500 error

    在arch 系统中安装perl-cgi包. 在deiban中参考:https://git-scm.com/book/zh/v2/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A ...

  10. skip-grant-tables 修改linux的mysql忘记root密码

    skip-grant-tables 修改linux的mysql忘记root密码 今天修改mysql中的admin用户权限,在执行update user set host =' %' where use ...