备忘:今天项目里又遇见一个之前就遇见过解决了后来又忘了的问题
关于vue获取图片
直接写路径也可以放在data里面
我的图片路径是在assets里面的
iconArr: [
{
title: "添加",
icon: require("@/assets/icon/png/icon1_slices/icon1.png"),
iconbgd: require("@/assets/icon/png/icon1_slices/icon11.png"),
},
{
title: "添加",
icon: require("@/assets/icon/png/icon1_slices/icon2.png"),
iconbgd: require("@/assets/icon/png/icon1_slices/icon22.png"),
},
{
title: "添加",
icon: require("@/assets/icon/png/icon1_slices/icon3.png"),
iconbgd: require("@/assets/icon/png/icon1_slices/icon33.png"),
},
{
title: "添加",
icon: require("@/assets/icon/png/icon1_slices/icon4.png"),
iconbgd: require("@/assets/icon/png/icon1_slices/icon44.png"),
},
这是在data中的``
<img
:src="iconSwitch == true ? item.iconbgd : item.icon"
alt=""
width="46px"
height="46px"
@click="iconSwitch = !iconSwitch"
/>