forked from xxxgitone/vue-node-pastime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (48 loc) · 1.3 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
// 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 store from './store/store'
import axios from './utils/axiosService'
import moment from 'moment'
import VueLazyload from 'vue-lazyload'
import './assets/scss/index.scss'
Vue.config.productionTip = false
Vue.prototype.$http = axios
moment.locale('zh-cn')
Vue.use(VueLazyload, {
loading: require('./assets/img/placeholder.png')
})
// 处理时间的全局过滤器
Vue.filter('timeAgo', timestamp => {
return moment(timestamp).startOf('hour').fromNow()
})
// 处理视频时长的过滤器
Vue.filter('durationFormat', duration => {
const min = parseInt(duration / 60)
const s = duration % 60
const time = s >= 10 ? `${min}:${s}` : `${min}:0${s}`
return time
})
// vue全局拦截器
router.beforeEach((to, from, next) => {
if (to.meta.requireAuth) { // 如果需要权限
if (store.getters.token) { // 存在的话,直接跳转过去
next()
} else {
next({ path: '/' })
store.commit('SHOW_SIGN_DIALOG')
}
} else {
next()
}
})
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
})