import Vue from 'vue'
import $ from 'webpack-zepto'
import router from './router'
import Alert from './libs/alert';
import FastClick from 'fastclick';
import _ from 'lodash';
Vue.use(Alert);
FastClick.attach(document.body);
Vue.config.productionTip = false
$.ajaxSettings.crossDomain = true;
// 登录中间验证,页面需要登录而没有登录的情况直接跳转登录 配和路由 index.js
router.beforeEach((to, from, next) => {
// 处理左侧滚动不影响右边
// $('html, body, #page').removeClass('scroll-hide');
$('body').css('overflow', 'auto');
if (to.matched.some(record => record.meta.requiresAuth)) {
if (userId) {
next();
} else {
next({
path: '/login',
query: { redirect: to.fullPath }
});
}
} else {
next();
}
});
new Vue({
el: '#app',
router
})
router index.js
import Vue from 'vue'
import Router from 'vue-router'
import index from '@/views/index'
import list from '@/views/list'
import login from '@/views/login'
import about from '@/views/about'
import message from '@/views/message'
import topic from '@/views/topic'
import user from '@/views/user'
Vue.use(Router)
export default new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'index',
component: index
},
{
path: '/login',
name: 'login',
component: login
},
{
path: '/message',
name: 'message',
component: message
},
{
path: '/about',
name: 'about',
component: about
},
{
path: '/list',
name: 'list',
component: list
// meta: {
// requiresAuth: true //配合 main.js 路由卫士使用
// }
},
{
path: '/user',
name: 'user',
component: user
},
{
path: '/topic/:id',
name: 'topic',
component: topic
}
]
})