vue圖片引入問題

在一些時候我們需要在方法中判斷是否顯示默認的本地圖片,這時圖片直接在方法中寫入會無法顯示,建議先使用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;
		}

	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章