[英]How to solve : [Vue warn]: Error when rendering component on the vue.js 2?
My component code ( SearchResultView.vue ) is like this : 我的组件代码( SearchResultView.vue )像这样:
<template>
...
</template>
<script>
export default{
props:['search','category','shop'],
created(){
...
},
data(){
return{
loading:false
}
},
computed:{
list:function(){
var a = this.$store.state.product;
a = JSON.stringify(a)
a = JSON.parse(a)
console.log(a.list[12])
...
}
},
methods:{
...
}
}
</script>
When I check this : console.log(a.list[12])
on the console, the result : 当我在控制台上检查以下内容时: console.log(a.list[12])
,结果是:
I want display value of name 我想要显示名称的值
I try like this : 我这样尝试:
console.log(a.list[12].name)
On the console, exist error like this : 在控制台上,存在如下错误:
[Vue warn]: Error when rendering component at C:\\xampp\\htdocs\\chelseashop\\resources\\assets\\js\\components\\SearchResultView.vue: [Vue警告]:在C:\\ xampp \\ htdocs \\ chelseashop \\ resources \\ assets \\ js \\ components \\ SearchResultView.vue渲染组件时出错:
Uncaught TypeError: Cannot read property 'name' of undefined 未捕获的TypeError:无法读取未定义的属性“名称”
How can I solve the error? 我该如何解决错误?
Because it is a computed, its value probably changes during the life of your program. 由于它是经过计算的,因此它的值可能会在程序生命周期中发生变化。 You should check to ensure that a.list[12]
exists before trying to get a member from it. 在尝试从中获取成员之前,应检查并确保a.list[12]
存在。
if (a.list[12])
console.log(a.list[12].name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.