使用方法:
(1)定义插件
创建一个单独的plugin.js文件,
应该暴露一个 install 方法。
这个方法的第一个参数是 Vue 构造器,
第二个参数是一个可选的选项对象
export default {
install(Vue) {
Vue.mixin({
methods: {
showName() {
alert(this.name);
},
},
})
Vue.directive('my-directive', {
bind (el, binding, vnode, oldVnode) {
}
...
})
Vue.prototype.$myMethod = function (methodOptions) {
}
Vue.filter('capitalize', function (value) {
if (!value) return ''
value = value.toString()
return value.charAt(0).toUpperCase() + value.slice(1)
})
}
}
(2)在main.js中
导入 import plugins from '../plugs'
使用插件 Vue.use(plugins)