乐趣区

关于javascript:vue-20-处理图片错误的情况-自定义指令

//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".....
退出移动版