2 Star 3 Fork 1

Billy / ShoppingMall 前端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.js 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
Billy 提交于 2022-01-22 00:40 . 前端
import Vue from 'vue';
import Vuex from 'vuex'
import App from './App';
import nodata from "./pages/commponent/public/nodata";
import store from './store';
Vue.prototype.$store = store
import request from 'utils/request.js' //引入异步请求函数
Vue.prototype.myrequest = request.request //挂载到全局
Vue.component("nodata", nodata);
Vue.config.productionTip = false;
//多次点击处理事件
import common from './common/index.js'
Vue.prototype.$noMultipleClicks = common.noMultipleClicks;
Vue.mixin({
methods: {
setData: function(obj, callback) {
let that = this;
const handleData = (tepData, tepKey, afterKey) => {
tepKey = tepKey.split('.');
tepKey.forEach(item => {
if (tepData[item] === null || tepData[item] === undefined) {
let reg = /^[0-9]+$/;
tepData[item] = reg.test(afterKey) ? [] : {};
tepData = tepData[item];
} else {
tepData = tepData[item];
}
});
return tepData;
};
const isFn = function(value) {
return typeof value == 'function' || false;
};
Object.keys(obj).forEach(function(key) {
let val = obj[key];
key = key.replace(/\]/g, '').replace(/\[/g, '.');
let front, after;
let index_after = key.lastIndexOf('.');
if (index_after != -1) {
after = key.slice(index_after + 1);
front = handleData(that, key.slice(0, index_after), after);
} else {
after = key;
front = that;
}
if (front.$data && front.$data[after] === undefined) {
Object.defineProperty(front, after, {
get() {
return front.$data[after];
},
set(newValue) {
front.$data[after] = newValue;
that.$forceUpdate();
},
enumerable: true,
configurable: true
});
front[after] = val;
} else {
that.$set(front, after, val);
}
});
isFn(callback) && this.$nextTick(callback);
}
}
});
App.mpType = 'app';
const app = new Vue({
...App
});
app.$mount();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/a2674442942/shopping-mall.git
git@gitee.com:a2674442942/shopping-mall.git
a2674442942
shopping-mall
ShoppingMall 前端
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891