插件文件toast.js
import Vue from 'vue';
/* js主体 */
let toast= function(options) {
this._name = 'name';
}
toast.prototype = {
VERSION: '0.0.1',
log: function(){
console.log(this._name)
},
get: function() {
return this._name
}
}
toast.create = function(options) {
return new toast(options);
}
/* js主体 */
let config = {};
const _toast = toast.create(config);
let Plugin = {};
Plugin.install = function (Vue, options) {
Vue.toast = _toast;
window.toast = _toast;
Object.defineProperties(Vue.prototype, {
toast: {
get() {
return _toast;
}
},
$toast: {
get() {
return _toast;
}
}
});
}
Vue.use(Plugin);
export default Plugin
main.js引入
import './plugins/toast'
使用
export default {
created() {
toast.log();
console.log(toast.get());
}
}
网友评论