-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmain.js
78 lines (70 loc) · 2.43 KB
/
main.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// 引入vue
import Vue from 'vue';
// 引入vue-router路由插件
import VueRouter from 'vue-router';
Vue.use(VueRouter); // 安装插件
// 引入Mint-ui
import MintUi from 'mint-ui';
import 'mint-ui/lib/style.css';
Vue.use(MintUi); // 安装插件
// 引入mui的css
import './static/vendor/mui/dist/css/mui.css';
// 引入自己的css
import './static/css/style.css';
// 引入axios
import Axios from 'axios';
// 添加请求拦截器
Axios.interceptors.request.use(function (config) {
// 在发送请求之前做些什么
MintUi.Indicator.open({ // 加载loading
text: '加载中...',
spinnerType: 'fading-circle'
});
return config;
}, function (error) {
// 对请求错误做些什么
return Promise.reject(error);
});
// 添加响应拦截器
Axios.interceptors.response.use(function (response) {
MintUi.Indicator.close(); // 去掉loading
// 对响应数据做点什么
return response;
}, function (error) {
// 对响应错误做点什么
return Promise.reject(error);
});
Vue.prototype.$ajax = Axios; // 可以使用this.$ajax
// 引入自己的全局组件
import App from './components/app.vue';
import Home from './components/home/home.vue';
import Information from './components/information/information.vue';
import Shopcar from './components/shopcar/shopcar.vue';
import Setting from './components/setting/setting.vue';
import NewsList from './components/news/newsList.vue';
import NewsDetail from './components/news/newsDetail.vue';
import PhotoShare from './components/photoShare/photoShare.vue';
import GoodsList from './components/goods/goodsList.vue';
// 配置路由对象
let router = new VueRouter();
router.addRoutes([
{name: 'default',path: '',redirect: {name: 'home'}}, // 默认
{name: 'home',path: '/home',component: Home}, // 首页
{name: 'information',path: '/information',component: Information}, // 消息
{name: 'shopcar',path: '/shopcar',component: Shopcar}, // 购物车
{name: 'setting',path: '/setting',component: Setting}, // 设置
{name: 'newsList',path: '/news/list',component: NewsList}, // 新闻列表
{name: 'newsDetail',path: '/news/detail/:newsId',component: NewsDetail}, // 新闻详情
{name: 'photoShare',path: '/photoShare',component: PhotoShare}, // 图片分享
{name: 'goodsList',path: '/goodsList',component: GoodsList}, // 商品展示
]);
// 引入配置好的mockjs
import './util/mock.js';
// 加入到vue实例中
new Vue({
el: '#app',
router: router,
render: (c) => {
return c(App);
},
});