Vue.use()

作者: Cherry丶小丸子 | 来源:发表于2023-02-05 14:41 被阅读0次

https://blog.csdn.net/ZYS10000/article/details/107246076/
https://blog.csdn.net/wswq2505655377/article/details/125148655
vue源码注释版:https://github.com/qq281113270/vue

function initUse (Vue) {

    // 1. Vue.use是一个函数
    Vue.use = function (plugin) {

        // 2. 定义一个数组 如果 this._installedPlugin 不存在,会执行 this._installedPlugins = []
        var installedPlugins = (this._installedPlugins || (this._installedPlugins = []));

        // 3. 判断是否已经注册了,已经注册了直接 return
        if (installedPlugins.indexOf(plugin) > -1) {
            return this
        }
    
    
        // 4.获取其他参数  例如:Vue.use(plugin,a,b,c) 中的 a b c
        var args = toArray(arguments, 1);

        // 5.参数第一项,加一个Vue实例进去
        args.unshift(this);

        // 6. plugin 有 install 这个方法
        if (typeof plugin.install === 'function') {
            // 7. 执行一下 instal,再把参数传递进去(可以看插件的 install 方法,接受第一个参数,就是 Vue 实例)
            plugin.install.apply(plugin, args);
        } else if (typeof plugin === 'function') {
            // 8. 如果 plugin 本身就是函数 直接执行
            plugin.apply(null, args);
        }

        // 9. 来一个数组存储已经注册的插件
        installedPlugins.push(plugin);
    
        return this
    };
}

相关文章

  • Vue.use源码

    官方对 Vue.use() 方法的说明: 通过全局方法 Vue.use() 使用插件;Vue.use 会自动阻止多...

  • Vue.use() 注册插件(个人笔记)

    Vue.use是什么? 官方对 Vue.use() 方法的说明:通过全局方法 Vue.use() 使用插件,Vue...

  • Vue.use, Vue.component,router-vi

    ? Vue.use Vue.use 的作用是安装插件 Vue.use 接收一个参数 如果这个参数是函数的话,Vue...

  • Vue.use源码数据流

    Vue.use(ElementUI)实现 step1:查看Vue.use 函数,其中我们看到 step2:查看pl...

  • 为什么axios不是使用的vue.use()

    问题 相信很多人在用Vue使用别人的组件时,会用到Vue.use()。例如:Vue.use(VueRouter)、...

  • 关于Vue.use()详细说明

    问题 相信很多人在用Vue使用别人的组件时,会用到Vue.use()。例如:Vue.use(VueRouter)、...

  • 关于Vue.use()详解

    问题相信很多人在用Vue使用别人的组件时,会用到 Vue.use() 。例如:Vue.use(VueRouter)...

  • VUE.use详解

    问题 相信很多人在用Vue使用别人的组件时,会用到 Vue.use() 。例如:Vue.use(VueRouter...

  • 关于Vue.use()详解

    问题 相信很多人在用Vue使用别人的组件时,会用到 Vue.use() 。例如:Vue.use(VueRouter...

  • 彻底弄懂 Vue.use() 方法

    相信很多人在用Vue使用别人的组件时,会用到 Vue.use() 。例如:Vue.use(VueRouter)、V...

网友评论

      本文标题:Vue.use()

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