首页 > 其他 > 详细

【vue开发】vue插件的install方法

时间:2019-09-16 13:20:24      阅读:277      评论:0      收藏:0      [点我收藏+]
MyPlugin.install = function (Vue, options) {
  // 1. 添加全局方法或属性
  Vue.myGlobalMethod = function () {
    // 逻辑...
  }

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

  // 3. 注入组件
  Vue.mixin({
    created: function () {
      // 逻辑...
    }
    ...
  })

  // 4. 添加实例方法
  Vue.prototype.$myMethod = function (methodOptions) {
    // 逻辑...
  }
}
import Vue from ‘vue‘

import VueI18n from ‘vue-i18n‘ Vue.use(VueI18n)

这里注意的就是vue插件的使用方法,通过全局方法 Vue.use() 使用插件。

插件通常会为 Vue 添加全局功能。插件的范围没有限制——一般有下面几种:添加全局方法或者属性;添加全局资源:指令/过滤器/过渡等;通过全局 mixin 方法添加一些组件选项;添加 Vue 实例方法,通过把它们添加到 Vue.prototype 上实现。

了解vue插件的install方法对我们写大型项目有很大帮助。

 

【vue开发】vue插件的install方法

原文:https://www.cnblogs.com/xiaohuizhang/p/11526444.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!