Vue图片加载失败设置默认图片
123
export default { avatar: require("@/assets/images/default/avatar.png")};
1234567891011121314
import Vue from "vue";import parameters from "parameters";Vue.directive("default-img", { bind: function(el, binding) { el.onerror = function() { let arg = parameters[binding.arg]; if (arg) { el.onerror = null; el.src = arg; } }; }});
<img v-default-img:avatar :src="Avatar" />