简介
将自定义的插件放到Vue实例原型上 Vue.prototype ,在 vm 或者 vc 调用实例方法使用插件
一、创建一个插件
创建一个 plug.js 文件
export default {
// xxx 方法
xxx() {
// ...
},
// yyy 方法
yyy() {
// ...
}
}
二、引入插件
在 main.js 文件中,引入插件
import plug from './util/plug'
Vue.prototype.$plug = plug
三、使用插件
export default {
name: 'plug',
mounted() {
this.$plug.xxx();
this.$plug.yyy();
},
}