前端前端
fabric
算法
jsBlock
styleBlock
svgBlock
工具其他
Vue、React相关
webgl
GitHub
fabric
算法
jsBlock
styleBlock
svgBlock
工具其他
Vue、React相关
webgl
GitHub
  • 1_1_nextjs项目开发
  • 1_2_nextjs项目部署
  • React
  • React使用中遇到的一些问题
  • React构建create-react-app简单说明
  • ubuntu使用
  • vue.init
  • vue.use
  • vuex源码解析
  • Vue使用中遇到的一些问题
  • vue梳理
  • watcher&&dep
  • 代码片段
  • 打包
  • 简单双向绑定
  • 纯函数

vue.use

注册组件两种方法

import Vuex from 'vuex'
Vue.use(Vuex)

import Echarts from 'echarts'
Vue.prototype.$echarts = Echarts

vue.use

export function initUse (Vue: GlobalAPI) {
  Vue.use = function (plugin: Function | Object) {
    const installedPlugins = (this._installedPlugins || (this._installedPlugins = []))
    if (installedPlugins.indexOf(plugin) > -1) {
      return this
    }

    // additional parameters
    const args = toArray(arguments, 1)
    args.unshift(this)
    if (typeof plugin.install === 'function') {
      plugin.install.apply(plugin, args)
    } else if (typeof plugin === 'function') {
      plugin.apply(null, args)
    }
    installedPlugins.push(plugin)
    return this
  }
}

vue.use(plugin), plugin为function 或者 object, function直接调用,object调install方法,第一个参数为vue

好处,可以在plugin install里面写更多的逻辑

import Echarts from 'echarts'
export default {
  install(Vue){
    Vue.prototype.$echarts = Echarts
    ...
  }
}
Edit this page
最近更新:: 2021/5/26 17:52
Contributors: wuhui
Prev
vue.init
Next
vuex源码解析