1.方法
var pluginUtil = {}
pluginUtil.install = function (Vue) {
Array.prototype.gRemove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
Vue.prototype.$gUtil = new (function () {
// 获取当前时间
this.getTimeNow = function () {
return new Date();
}
//比较大小,返回最小的值
this.compareAndS = function(a,b){
if(a>b){
return b;
}else{
return a;
}
}
})()
}
export default pluginUtil
2.引用
在main.js中
import pluginUtil from ‘./utils/pluginUtil’;
Vue.use(pluginUtil);
3.使用
let arr = [‘qwe’,‘a’,‘rrrr’,‘b’];
arr.gRemove(‘a’);
console.log(arr)
let time = this.$gUtil.getTimeNow();
let ss = this.$gUtil.compareAndS(110,150);
console.log(ss);
console.log(time);