// 加载图片
import avatar from '@/assets/images/avatar.png'
export default {
	name: 'avatarLoad',
	mounted(el, binding) {
		loadImage(el, binding.value)
	},
	updated(el, binding) {
		// 当 binding.value 发生变化时重新加载
		if (binding.oldValue !== binding.value) {
			loadImage(el, binding.value)
		}
	},
};
function loadImage(el, src) {
	if (!src) return
	
	const img = new Image()
	img.src = src
	img.onload = () => {
		el.src = src
	}
	img.onerror = () => {
		el.src = avatar // 默认头像
		console.log('图片加载失败:', src)
	}
}