diff --git a/src/directives/index.js b/src/directives/index.js new file mode 100644 index 0000000..dd0486c --- /dev/null +++ b/src/directives/index.js @@ -0,0 +1,11 @@ +import Vue from 'vue' +// 全局指令: 图片加载失败 +Vue.directive('imgerror', { + // dom被插入到组件中时, 第二个参数 + inserted(el, options) { + // console.log(el) + el.onerror = function() { + el.src = options.value + } + } +}) diff --git a/src/layout/components/Navbar.vue b/src/layout/components/Navbar.vue index ebb4cc3..b1cb5d6 100644 --- a/src/layout/components/Navbar.vue +++ b/src/layout/components/Navbar.vue @@ -11,7 +11,7 @@