css里的item.type引用不到 总是报错
来源:17-1 布局编写

慕运维2559375
2019-07-20
[Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"
<template>
<div class="goods">
<aside class="aside-menu">
<ul>
<li v-for="item in goods" class="menu-item">
<span class="text">
<span v-show="item.type>0" class="icon-item" v-bind:style="{background: iconMap[item.type].textColor }">
{{iconMap[item.type].iconText}}
</span>{{item.name}}
</span>
</li>
</ul>
</aside>
<div class="foods-content">
</div>
</div>
</template>
<script>
const ERR_OK = 0
export default {
props:{
seller:{
type: Object
}
},
data(){
return {
goods: {}
}
},
created() {
this.iconMap = [
{
iconText: '减',
textColor: 'rgb(240,20,20)',
name:'red'
},
{
iconText: '折',
textColor: '#EEC900',
name:'yellow'
},
{
iconText: '特',
textColor: '#6495ED',
name:'blue'
},
{
iconText: '票',
textColor: '#66CDAA',
name:'green'
},
{
iconText: '保',
textColor: '#BF3EFF',
name:'purple'
}];
this.$http.get('/api/goods').then((response) => {
response = response.body
if (response.errno === ERR_OK) {
this.goods = response.data
}
})
},
name: 'goods'
}
</script>
<style>
.goods{
display: flex;
position: absolute;
top: 182px;
bottom: 64px;
width: 100%;
overflow: hidden;
}
.aside-menu {
flex: 0 0 80px;
width: 80px;
background: #f3f5f7;
}
.foods-content{
flex: 1;
}
.menu-item{
display: flex;
justify-content: center;
align-items: center;
padding: auto 12px;
height: 54px;
position: relative;
}
.menu-item:not(:last-child)::after{
content: '';
position: absolute;
height: 1px;
width: 56px;
padding: auto 12px;
background: rgba(7,17,27,.1);
bottom: 0;
}
.menu-item:first-child{
color: rgb(240,20,20);
}
.icon-item{
display: inline-block;
width: 14px;
height: 14px;
border-radius: 4px;
flex: 0 0 14px;
}
.menu-item .text{
font-size: 12px;
/*display: flex;*/
width: 56px;
line-height: 14px;
}
</style>
写回答
2回答
-
你在哪儿加的 v-if
052019-07-22 -
慕运维2559375
提问者
2019-07-20
已经解决 v-show改为v-if 但是我想知道为什么 老师可以解答一下么
00
相似问题
app.vue中引入1px报错
回答 2
关于全局引入stylus的问题
回答 2
在main.js中引入index文件报错
回答 1
为什么这里不用加v-if
回答 1
为什么我的icon 引不进来
回答 3