通常有两种情况:

1、在模板的html标签上使用length报错

vue 中使用 length判断的时候,有时会报错,如下:

<div class="item_list" v-if="form.checkVal.length > 0" >列表1</div>
<div class="item_list" v-else >列表2</div>
解决方法:

改成:  form.checkVal !== undefined  &&  form.checkVal.length > 0

<div class="item_list" v-if="form.checkVal !== undefind && form.checkVal.length > 0" >列表1</div>
<div class="item_list" v-else >列表2</div>
2、在js中使用length报错,如下

if(res.Data.length == 1){
this.tableData1 = res.Data[0];
}
报错原因:此时res.Data是无数据为undefined的,所以找不到 res.Data.length。

解决办法:在加一层判断,首先保证res.Data存在不为null或undefined改为,如下

if(res.Data){
if(res.Data.length == 1){
this.tableData1 = res.Data[0];
}

3.可能在data中声明了两个相同的属性,导致冲突,或者写错某个单词导致没有数据

4.判断是否存在

<div v-if="poiInfo2.discounts2"><img :src="poiInfo2.discounts2[0].icon_url" >{{poiInfo2.discounts2[0].info}} </div>

vue报错Error in render: "TypeError: Cannot read property '0' of undefined"的更多相关文章

  1. [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined、vuejs路由使用的问题Error in render function

    1.[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined 注意,只要出现Error i ...

  2. Vue 报错Error in render: “TypeError: Cannot read properties of null (reading ‘xxx’)” found in

    前端vue报错 [Vue warn]: Error in render: "TypeError: Cannot read properties of null (reading 'name' ...

  3. app.js:1274 [Vue warn]: Error in render: "TypeError: Cannot read property 'object_id' of undefined"问题小记

    凌晨遇到一个控制台报错的信息,总是显示有对象中的元素未定义 明明是有把定义对象的值的,后面发现是把没有返回值的函数又赋值一遍给未定义的元素所属的对象,

  4. vue2.XX 提示[Vue warn]: Error in render: "TypeError: Cannot read property 'img' of undefined"

    item 是向后台请求的一条数据,里面包含img,但是却提示img未定义 父组件向子组件传递数据时, 子组件 具体代码: <img :src="item.img" /> ...

  5. [Vue warn]: Error in render: "TypeError: Cannot read property 'matched' of undefined" found in <App> at src/App.vue

    当用Vue模块化开发时,输入  http://localhost:8080  页面没有显示,首先按F12,检查是否有如下错误 话不多说,直接看下面: 解决方法1 如果是上面出的问题,以后就要注意了哦, ...

  6. Error in render: "TypeError: Cannot read property 'url_img' of undefined"

    如果我们 vue 组件中 template 里面添加了下标(靠数组索引得到的值),就会报索引为 undefined 解决方法: 在我们使用下标时,要在父组件上做条件判断,如果这个下标存在,然后就显示里 ...

  7. Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol')

    Vue报错: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'protocol') 报错信 ...

  8. vue运行报错error:Cannot assign to read only property 'exports' of object '#<Object>'

    用weex做项目的时候,npm start 之后一直报错error:Cannot assign to read only property 'exports' of object '#<Obje ...

  9. vue报错-Error: Cannot find module '@babel/core'

    vue之webpack实战的时候遇到报错,Error: Cannot find module '@babel/core' 这报错,我百度了很久,后来发现报错里面有提示,发现是我的 babel-load ...

随机推荐

  1. 好用的开源库(一)——MaterialEditText

    GIthub地址:https://github.com/rengwuxian/MaterialEditText#features 使用文档: 在android新推出的Material Design中对 ...

  2. 【eclipse】eclipse报错:the resource is not on the build path of a java project

    最近在eclipse中,使用svn导入svn上的一个maven项目,但是导入后类的包并没有以源码包的方式显示,而是以普通文件包的方式显示出来,在对类进行F3等操作时就报错:“the resource ...

  3. mybatis基础(下)

    mybatis和spring整合 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSe ...

  4. 【20190415】JavaScript-事件流与stopPropagation()、stopImmediatePropagation()的误区解析

    这两天仔细看了一下MDN上关于事件流机制和相关方法的文档,发现有个很大的误区.过去我一直以为stopPropagation()就是用来阻止事件冒泡的,甚至很多博客和菜鸟教程上都是这样写的.但实际上文档 ...

  5. 广州.NET微软技术俱乐部微信群有用信息集锦(10) - 大量json数据压缩方案

    这是广州.NET微软技术俱乐部微信群有用信息集锦系列的其中一篇文章.   刚才微信群里有人问:“对于大量json数据返回的时候,有用过什么压缩方案吗?”   大家都给与了回答和帮助.包括: 开启gzi ...

  6. 模拟ES6中的Promise实现,让原理一目了然

    简介 Promise 对象用于延迟(deferred) 计算和异步(asynchronous )计算.一个Promise对象代表着一个还未完成,但预期将来会完成的操作.Promise 对象是一个返回值 ...

  7. centos7个人shell编写环境

    一.配置存放文件/root/wang 存放常用的文件/root/wang/shell 存放练习的shell文件/root/wang/succeed_shell 存放有用shell文件/root/bak ...

  8. c/c++ linux epoll系列1 创建epoll

    linux epoll系列1 创建epoll 据说select和poll的弱点是,随着连接(socket)的增加,性能会直线下降. epoll不会随着连接(socket)的增加,性能直线下降. 知识点 ...

  9. python--多继承

    多继承 子类可以拥有多个父类,继承所有父类的属性和方法 class 子类名(父类名1,父类名2): 多个父类直接不要有重名的方法和属性,子类对象调用,没法确认.

  10. MongoDB的常用命令和增查改删

    数据库操作 Mongodb MySQL 查询库 show databases | show dbs show databases 选中库 use databaseName use databaseNa ...