zoukankan      html  css  js  c++  java
  • 【vue开发】vue插件的install方法

    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方法对我们写大型项目有很大帮助。

  • 相关阅读:
    分布式事物的解决方法
    bootstrap的其他
    bootstrap表单控件
    多线程编程
    内存管理技术
    PrintWriter用法简析
    JSP内置对象
    Servlet学习应该注意的几点
    GPU渲染管线概述
    再说AutoComplete
  • 原文地址:https://www.cnblogs.com/xiaohuizhang/p/11526444.html
Copyright © 2011-2022 走看看