vue 2.0_ 处理图片错误的情况, (自定义指令)
文章目录
//directive.js
export const imageerror = {
inserted(dom, options) {
// debugger
dom.onerror = function() {
dom.src = options.value
}
}
}
ex....main.js
import * as directives from '@directive'
Object.keys(directives).forEach(key => {
Vue.directive(key, directives[key])
})example
<img v-imageerror="defaultImg".....
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论