错误写法:
main.js
Vue.prototype.$imgUrl = '图片地址'
这么写之后 就发现压根不起作用;获取到的是undefined
正确写法:
返回函数,后面可以拼上OSS图片完整路径
Vue.prototype.$imgUrl = (url) => {
return ("https://地址" + url);
};
页面使用:
template
<image :src="$imgUrl('/list-icon.png')" />
js
this.$imgUrl('/list-icon.png')
css定义
uni.scss
$imgUrl: "https://图片地址";
style使用:
background: url($imgUrl + "/modal.png") no-repeat;