64abdf01 by simon

挂载全局app 让api与小程序一致

1 parent 45cb2495
module.exports = {
testListGet: '/xxx/xxx/list'
testListGet: '/xxx/xxx/list',
areaQuery: 'https://api.k.wxpai.cn/bizproxy/kdapi/area', // post 区域查询
}
\ No newline at end of file
......
import Vue from 'vue'
import App from './App.vue'
import VueApp from './App.vue'
import router from './router'
import store from './store'
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
// import Mock from './mock'
// Mock.bootstrap();
......@@ -44,11 +50,21 @@ Vue.use(Swipe).use(SwipeItem)
.use(Button)
.use(Toast);
new Vue({
let app = new Vue({
router,
store,
data: {
isInit: false,
},
render: h => h(App)
}).$mount('#app')
\ No newline at end of file
render: h => h(VueApp)
}).$mount('#app')
// 挂载全局app
app.api = api;
app.get = httpGet;
app.post = httpPost;
app.router = router;
window.app = app;
// 原app节点请通过 document.getElementById('app') 获取
// routes里的component组件需要以import方式引入,否则页面创建的时候,app还没挂载。
\ No newline at end of file
......
import api from '../../api/api'
import {
httpGet,
httpPost
} from '../../api/fetch-api.js'
export default {
data() {
return {
......
import api from '../../api/api'
import {
httpGet,
httpPost
} from '../../api/fetch-api.js'
export default {
data() {
return {
......@@ -12,12 +6,12 @@ export default {
},
components: {},
methods: {
initData() {},
toLottery() {
this.$router.push({
path: "/lottery"
})
}
app.router.push({
name: "lottery"
});
},
initData() {},
},
mounted() {},
created() {
......
import api from '../../api/api'
import {
httpGet,
httpPost
} from '../../api/fetch-api.js'
export default {
data() {
return {
......@@ -18,7 +12,18 @@ export default {
path: "/"
})
},
async queryArea() {
let res = await app.post({
url: app.api.areaQuery,
data: {},
sid: false,
mode: "custom"
});
console.log("地区查询:", res);
}
},
mounted() {
this.queryArea();
},
mounted() {},
created() {}
}
\ No newline at end of file
......
import Vue from 'vue'
import Router from 'vue-router'
import Index from './pages/index/index.vue'
Vue.use(Router)
const routes = [{
path: '/',
name: 'index',
component: Index,
component: () => import('./pages/index/index.vue'),
meta: {
title: ''
}
......