问题记录:v-for循环获取img src变量动态渲染时,不显示图片
<li v-for="(item,index) in menuData" :key="item.id"> <div> <img :src="item.iconPath" alt=""> </div> </li>
<script>
export default {
data() {
return {
menuData: [{
iconPath: ('@/assets/img/layout.png'),
}]
}
}
}
</script>
解决方案:data中的数据加上require()
<li v-for="(item,index) in menuData" :key="item.id"> <div> <img :src="item.iconPath" alt=""> </div> </li> <script> export default { data() { return { menuData: [{ iconPath:require('@/assets/img/layout.png'),
}]
}
}
}
</script>