参考: https://blog.csdn.net/qq_37130872/article/details/128133646
- useImages.js
// 获取assets静态图片
export const getAssetsImge = (name) => {
return new URL("../assets/" + name + ".png", import.meta.url).href
}
- 使用
<img class="user-icon" :src="`${userPicture ? userPicture : avatarUrl}`" alt="">
import {getAssetsImge} from '@/utils/useImage.js';
computed: {
avatarUrl() {
return getAssetsImge('user-avatar');
}
},
标签:Vue,assets,avatarUrl,avatar,getAssetsImge,png,user
From: https://www.cnblogs.com/openmind-ink/p/17164750.html