Skip to content

Suggestion about using a plugin in a single project contains multi versions of vue #5970

@LancerComet

Description

@LancerComet

What problem does this feature solve?

A project may contains different versions of Vue, but the designing of plugin system is not designed for that.

The plugin would be available for only one vue library, no matter how many vue libs you require.

// My Plugin.
export default {
  install (Vue, options) {
    Vue.doSomething = function () {...}
  }
}
// Module 01 in my project.
import Vue from 'vue'  // Maybe vue 2.2
import MyPlugin from 'my-plugin'

Vue.use(MyPlugin)
Vue.doSomething()  // Yeah.
// Module 02 in my project.
import Vue from 'vue'  // Maybe vue 2.3.
import My Plugin from 'my-plugin'

Vue.use(MyPlugin)  // It doesn't work because "installed" has already been set to "true".
Vue.doSomething()  // Boom! Undefined!

What does the proposed API look like?

So this is what I'm doing:

// My Plugin.
export default function () {
  return {
    install (Vue, options) {
       Vue.doSomething = function () {...}
    }
  }
}
// Module 01 and 02 in my project.
import Vue from 'vue'
import MyPlugin from 'my-plugin'

Vue.use(MyPlugin())
Vue doSomething()  // Yeah!

Same as "data" properity.

Hope can be improved.😀

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions