1.Vue.use()
Plug-in development method demo
Plug-in. Js
export default {
install(vue, options) {
vue.prototype.someMethod = function(args) {
//do something
}
}
}
Copy the code
main.js
import xxx from 'xxx/xxx'
Vue.use(xxx);
Copy the code
use
this.someMethod(args)
Copy the code
This approach provides a global approach to code reuse.
The vue.use () method can also pass in a method directly, but that method will be executed immediately.
Vue.use(function(args){
//do something...
})
Copy the code
The source code is shown below
Different logic processing through if condition judgment.