The main technology stack of the new company is VUE. Although I have been working more deeply in React-Native in recent years, I will be safe now. Let’s start to learn and share more

Use () : use() : use() : use() : use() : use() : use(

function initUse (Vue) {
    Vue.use = function (plugin) {
      var installedPlugins = (this._installedPlugins || (this._installedPlugins = []));
      if (installedPlugins.indexOf(plugin) > -1) {
        return this
      }

      // additional parameters
      var 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
    };
  }
Copy the code

As you can see, this is simple. The argument passed to vue.use(plugin) has a feature with the install method, which is called in vue.use() to implement the injection of the plug-in. Also, use automatically prevents multiple registrations of the same plug-in, so that the plug-in is registered only once even if it is invoked multiple times.

Some official vue.js plug-ins (such as vue-router) automatically call vue.use () when detecting that vue is an accessible global variable. However, in a modular environment like CommonJS, you should always explicitly call vue.use ().

For example, axios cannot use vue.use(). Why not?