通常有两种情况:

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. [日常] Go-逐行读取文本信息

    go逐行读取文本信息:1.os包提供了操作系统函数的不依赖平台的接口,Open方法打开一个文件用于读取,func Open(name string) (file *File, err error)2. ...

  2. 学JAVA第四天,JAVA获取年月日

    先添加引用import java.util.Calendar; 然后编写代码: Calendar calendar = null;//声明 calendar= Calendar.getInstance ...

  3. FrameSet定义页面宽度并且居中

    frameset定义一个1000px的页面并且居中 <frame src = "about:blank"></frame> : 这个语句的功能是在一个框架里 ...

  4. java开发环境配置——Maven

    前篇讲了jdk的安装,这篇讲一下包管理工具Maven,Maven主要是用来统一管理项目引用的jar包,还有用来打包的. Maven官网下载地址:http://maven.apache.org/down ...

  5. jsp基础语言-jsp异常

    JSP异常 jsp页面执行时会出现两种异常,实际是javax.servlet.jsp包中的两类异常JsError和JspException. 1.JsError 在jsp文件转换成servlet文件时 ...

  6. 解决VS2017不连接visual studio emulator for android

      参考: http://blog.csdn.net/allen_xu5320/article/details/47280457   查出IP 直接ADB连上去                

  7. 0.react学习笔记-环境搭建与脚手架

    0.环境搭建 笔者使用的是deepin/mac两种系统,因为两个电脑经常切换用.环境搭建没什么区别. 0.1 node安装 按照node官网叙述安装 # Using Debian, as root c ...

  8. 微信小程序(五) 利用模板动态加载数据

    利用模板动态加载数据,其实是对上一节静态数据替换成动态数据:

  9. Ehcache入门经典:第二篇ehcache.xml的参数

    继续第一篇 diskStorepath:指定在硬盘上存储对象的路径path属性可以配置的目录有: user.home(用户的家目录) user.dir(用户当前的工作目录) java.io.tmpdi ...

  10. 数据库H2学习

    本文转载自:https://www.cnblogs.com/xdp-gacl/p/4171024.html 一.H2数据库介绍 常用的开源数据库有:H2,Derby,HSQLDB,MySQL,Post ...