在使用resetField 报错Cannot read property 'indexOf' of undefined

elementUI  的resetField  是对对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 ,当内容不一致 或找不到内容时 就会报错,具体原因举例如下:

原因1:ruleForm 内部数据 与实际页面需要验证的数据不一致 比如:下面例子 页面需要的是name ,而 ruleForm定义的是name2,当单词不小心写错就会报这个问题

 <el-form
        ref="newFormModel"
        :rules="rules"
        :model="ruleForm"
        :inline="true"
        style="width: calc(100%-50px); margin-left:50px;"
        min-width="1158px"
        class="demo-ruleForm"
      >
        <el-form-item label="Name" prop="name" class="my-el-form-item">
          <el-input v-model="newObj.name" placeholder="">
          </el-input>
        </el-form-item>
        <br>
        <el-form-item label="Country" prop="country" class="my-el-form-item">
          <el-input v-model="newObj.country" placeholder="">
          </el-input>
        </el-form-item>
</el-form>

script
 ruleForm: {
     name2: ‘‘,
     country: ‘‘
 },

原因二:当表单有v-if 根据表单内部数据去控制是否显示时 会存在这个问题 

解决方案:1 使用 v-show 代替 v-if;

2 使用 clearValidate  移除表单项的校验结果。对有验证的字段进行清空验证error 内容,对不需要验证的字段进行手动的初始化;

或者使用以上两种方式结合 ,看自己项目的需要

在使用resetField 报错Cannot read property 'indexOf' of undefined

原文地址:https://www.cnblogs.com/xhliang/p/11693111.html

时间: 2024-08-28 17:02:59

在使用resetField 报错Cannot read property 'indexOf' of undefined的相关文章

Chrome下使用百度地图报错Cannot read property &#39;minZoom&#39; of undefined

问题:工作中在Google chome下面的js console里面测试百度地图API var map = new BMap.Map("container"); map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); TypeError: Cannot read property 'minZoom' of undefined message: "Cannot read property 'minZoom' of unde

echarts报错Cannot read property &#39;features&#39; of undefined

引入地图的时候 echarts2报错: Uncaught Error: [MODULE_MISS]"echarts/src/util/mapData/params" is not exists! 原因不明,但是感觉和缺js文件有关(因为echarts3报错就是因为缺少了world.js) echarts3报错: Uncaught TypeError: Cannot read property 'features' of undefined 原因如下:缺少world.js,然后成功: 完

使用vue-preview报错Cannot read property &#39;open&#39; of undefined

最近在做一个vue项目中时,需要使用vue-preview插件制作缩略图,首先在终端使用npm i vue-preview -S指令安装了vue-preview插件,然后在main.js中,导入并引用: import VuePreview from 'vue-preview' Vue.use(VuePreview) 接着在需要用到vue-preview插件的组件中写入: <img class="preview-img" v-for="(item, index) in l

使用UEditor 报错Cannot read property &#39;nodeType&#39; of undefined 解决办法

报如下错误 解决办法: //对编辑器的操作最好在编辑器ready之后再做 ue.ready(function() { }) <!-- 实例化编辑器 --> <script type="text/javascript"> $(function(){ var ue = UE.getEditor("container",{ autoHeight: false }); /对编辑器的操作最好在编辑器ready之后再做 ue.ready(function

angular ng build 报错 Cannot read property &#39;default&#39; of undefined

95% emitting index-html-webpack-plugin Cannot read property 'default' of undefinedTypeError: Cannot read property 'default' of undefined at compiler.hooks.emit.tapPromise (E:\projects\node_modules\@angular-devkit\build-angular\src\angular-cli-files\p

dubbo-admin-2.5.3 运行报错: Bean property &#39;URIType&#39; is not writable or has an invalid

因为 jdk 是1.8的版本,和 dubbo-admin 存在兼容性问题.所以报错: Bean property 'URIType' is not writable or has an invalid 参见:https://github.com/alibaba/dubbo/issues/50 解决方法,修改 tomcat 默认的 jdk到 1.7 : 1) 修改bin文件夹下面的catalina.bat文件,把如下内容rem ----- Execute The Requested Command

Eclipse报错:Setting property &#39;source&#39; to &#39;org.eclipse.jst.jee.server:fzxt_tj&#39; did not find

在eclipse中启动tomcat时出现Setting property 'source' to 'org.eclipse.jst.jee.server:你的站点名'   did not find a matching property错误 解决办法: 1.在server控制台内,在服务器上点右键--属性 2.general选项卡中点switch location 这时,location变为:/servers/tomcat6.0 server at localhost.server 3.在pro

echarts js报错 Cannot read property &#39;getAttribute&#39; of null

本文将为您描述如何解决 eharts.js报错 Uncaught TypeError: Cannot read property 'getAttribute' of null 的问题 根据报错信息查找原因发现是因为 实例化 echarts 的元素不存在(未找到指定的元素),查看官方文档发现: // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); 基于准备好的 dom,初始化 e

UEditor使用报错Cannot set property &#39;innerHTML&#39; of undefined

仿用UEditor的setContent的时候报错,报错代码如下Uncaught TypeError: Cannot set property 'innerHTML' of undefined.调试ueditor.config.js,ueditor.all.js 提示me.body is undefined.(我就纳了闷儿了!同样的使用那个行这个咋就不行,那个有body,view,这个咋就这么少![我还查看了插件的内部函数,真是个good媛~])错误的原因是没有等UEditor创建完成就使用UE