美文网首页
vue如何引入自定义插件

vue如何引入自定义插件

作者: who_are_you_ | 来源:发表于2020-01-06 10:34 被阅读0次
  // 1. 添加全局方法或属性
  Vue.myGlobalMethod = function () {
    // 逻辑...
  }

  // 2. 添加全局资源
  Vue.directive('my-directive', {
    bind (el, binding, vnode, oldVnode) {
      // 逻辑...
    }
    ...
  })

  // 3. 注入组件
  Vue.mixin({
    data() {
            return {}
    },
    created: function () {
      // 逻辑...
    },
    methods: {
      //定义方法
       $log: console.log
    }

    ...
  })

  // 4. 添加实例方法
  Vue.prototype.$myMethod = function (methodOptions) {
    // 逻辑...
  }
}
export default MyPlugin;

相关文章

网友评论

      本文标题:vue如何引入自定义插件

      本文链接:https://www.haomeiwen.com/subject/kqwhactx.html