index.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file 项目入口文件
*/
import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import routes from './routes'
import store from './store'
import App from 'modules/app/index.vue'
import './landscape.js'
import './ipadLandscape.js'
import './common'
import './filters'
import 'styles/common.css'
import 'styles/commonStyle.css'
Vue.use(VueRouter)
Vue.use(Vuex)
import 'vant/es/toast/style';
import { Toast, Popup } from "vant";
Vue.use(Toast);
Vue.use(Popup);
// 配置发送请求拦截器,实现路由切换后取消之前的请求
let axiosPromiseArr = [];
import axios from 'axios'
axios.interceptors.request.use(config => {
config.cancelToken = new axios.CancelToken(cancel => {
axiosPromiseArr.push({ cancel });
})
return config;
}, err => {
var error = { message: '网络异常,请刷新重试', err: err, type: 'requestError' };
console.log(error);
return Promise.reject(error);
})
var Router = new VueRouter({ routes });
Router.beforeEach((to, from, next) => {
axiosPromiseArr.forEach((ele, index) => {
ele.cancel();
delete axiosPromiseArr[index];
})
next()
})
new Vue({
el: '#app',
render: h => h(App),
router: Router,
store: new Vuex.Store(store),
})