main.js
1.5 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
55
56
57
58
59
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
import App from "./App";
import router from "./router";
import Vant from "vant";
import "vant/lib/index.css";
Vue.use(Vant);
// import Vconsole from "vconsole";
// let vConsole = new Vconsole();
// Vue.use(vConsole);
import { service } from "./utils/commonsec.js";
Vue.prototype.$http = service;
// sessionStorage.setItem(
// "token",
// "85354709f184e1471f90a2048eb07b0f6cab95df279ec53d26b642ad080eed4d"
// );
import axios from "./utils/common.js";
Vue.prototype.$axios = axios;
if (sessionStorage.getItem("token")) {
axios.defaults.headers.common["token"] = sessionStorage.getItem("token");
}
import uploadFile from "./utils/common.js";
Vue.prototype.$uploadFile = uploadFile;
Vue.config.productionTip = false;
let token = sessionStorage.getItem("token");
router.beforeEach((to, from, next) => {
const token = sessionStorage.getItem("token");
console.log("我是token", token);
console.log(to);
console.log(next());
if (!token) {
if (to.path === "/login") {
next();
} else {
sessionStorage.setItem("now_url", to.fullPath); //当前页url与参数放入缓存
next("/login");
}
} else {
next();
}
});
/* eslint-disable no-new */
new Vue({
el: "#app",
router,
components: { App },
template: "<App/>"
});