当你在el-table中或其他情况下使用你在data里面定义的一个数据列表,并且其中包含了图片字段,在data里面赋值的时候,直接写image_url:'@/assets/images/test.png'
,在渲染的时候发现哎?它*的怎么不生效?我路径没错啊?当你用线上地址的时候不会出现这个问题。
解决方法就是,需要你写成require('@/assets/images/background.png')
这种形式。
以el-table为例:
引用的代码
<el-table :data="dataLast">
<el-table-column label="商品图片">
<template slot-scope="scope">
<el-image class="goods-img" :src="scope.row.image" lazy-load="false"></el-image>
</template>
</el-table-column>
</el-table>
不生效代码:
dataLast: [
{
id: 0,
image: '@/assets/images/background.png',// 我不生效
spec: '30',
price: '22.00',
total_stock: 21,
nomore_stock: 11,
warning_stock: 22,
},
]
有效代码:
dataLast: [
{
id: 0,
image: require('@/assets/images/background.png'), // 我没有问题
spec: '30',
price: '22.00',
total_stock: 21,
nomore_stock: 11,
warning_stock: 22,
}
],