在一些時候我們需要在方法中判斷是否顯示默認的本地圖片,這時圖片直接在方法中寫入會無法顯示,建議先使用import將圖片地址引入,再將該變量賦值給src對應的變量。
錯誤:
<img :src="userPic" />
computed: {
userPic() {
if(this.evaluateList.length != 0){
return this.evaluateList.headImage;
}else{
return '../../assets/[email protected]';
}
}
正確:
<img :src="userPic" />
import picsrc from '../../assets/[email protected]';
data() {
return {
userDefaultPic: picsrc
}
},
computed: {
userPic() {
console.log(this.evaluateList.length)
if(this.evaluateList.length != 0) {
let headImage = this.evaluateList.headImage;
console.log(this.evaluateList)
console.log(typeof(headImage));
console.log(headImage);
let indexstr = headImage.indexOf('app');
console.log(indexstr);
if(indexstr == -1) {
return this.evaluateList.headImage;
} else {
let pic = 'http://ralfael.com/' + this.evaluateList.headImage;
return pic;
}
} else {
return this.userDefaultPic;
}
}
}