优化部分代码
This commit is contained in:
parent
3a378f6589
commit
db8df33436
|
@ -1,5 +1,5 @@
|
|||
import Vue from "vue"
|
||||
import store from "@/store/index";
|
||||
let prototype = Vue.prototype;
|
||||
|
||||
function findRule(name) {
|
||||
let pos = name.indexOf('.');
|
||||
|
@ -7,7 +7,7 @@ function findRule(name) {
|
|||
let temp, arr = name.split('.');
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (i == 0) {
|
||||
temp = Vue.prototype.$apis[arr[i]] || {};
|
||||
temp = prototype.$apis[arr[i]] || {};
|
||||
} else {
|
||||
temp = temp[arr[i]] || {};
|
||||
}
|
||||
|
@ -24,19 +24,19 @@ const request = async (args) => {
|
|||
throw "找不到API:" + args.api;
|
||||
}
|
||||
|
||||
if (rule.auth && !store.state.user.token) {
|
||||
Vue.prototype.$store.commit("user/showLoginModal", true);
|
||||
if (rule.auth && !prototype.$store.state.user.token) {
|
||||
prototype.$store.commit("user/showLoginModal", true);
|
||||
return;
|
||||
}
|
||||
|
||||
const headers = {
|
||||
"XX-Wxapp-AppId": Vue.prototype.$config.appId,
|
||||
'XX-Token': store.state.user.token,
|
||||
"XX-Wxapp-AppId": prototype.$config.appId,
|
||||
'XX-Token': prototype.$store.state.user.token,
|
||||
'XX-Device-Type': 'wxapp',
|
||||
};
|
||||
|
||||
const [error, response] = await uni.request({
|
||||
url: Vue.prototype.$config.root + rule.url,
|
||||
url: prototype.$config.root + rule.url,
|
||||
method: rule.method || 'get',
|
||||
data: args.data,
|
||||
header: {
|
||||
|
|
|
@ -3,6 +3,7 @@ import App from './App'
|
|||
|
||||
import store from "./store/index"
|
||||
import request from './core/request'
|
||||
import test from './core/libs/test'
|
||||
import event from './core/libs/event'
|
||||
import utils from './core/libs/utils'
|
||||
import config from './core/config'
|
||||
|
@ -13,6 +14,7 @@ import './static/iconfont/iconfont.css'
|
|||
Vue.use({
|
||||
install(Vue, options) {
|
||||
Vue.prototype.$request = request
|
||||
Vue.prototype.$test = test
|
||||
Vue.prototype.$event = event
|
||||
Vue.prototype.$utils = utils
|
||||
Vue.prototype.$config = config
|
||||
|
|
Loading…
Reference in New Issue