fixed 版本无法显示问题

This commit is contained in:
marvzhang
2020-01-28 09:52:57 +08:00
parent 6d98e719f3
commit 1317f8d618
5 changed files with 33 additions and 9 deletions

View File

@@ -34,13 +34,7 @@ export default {
}
},
methods: {},
async created () {
await this.$store.dispatch('setting/getSetting')
},
async mounted () {
const res = await this.$request.get('/version')
this.version = res.data.data
sessionStorage.setItem('v', this.version)
window.setUseStats = (value) => {
document.querySelector('.el-message__closeBtn').click()
if (value === 1) {

View File

@@ -1,6 +1,8 @@
import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
import request from '../api/request'
import stats from '../utils/stats'
/* Layout */
@@ -257,8 +259,13 @@ router.beforeEach((to, from, next) => {
}
})
router.afterEach((to, from, next) => {
router.afterEach(async (to, from, next) => {
if (to.path) {
await store.dispatch('setting/getSetting')
const res = await request.get('/version')
const version = res.data.data
store.commit('version/SET_VERSION', version)
sessionStorage.setItem('v', version)
stats.sendPv(to.path)
}
})

View File

@@ -14,6 +14,7 @@ import lang from './modules/lang'
import site from './modules/site'
import stats from './modules/stats'
import setting from './modules/setting'
import version from './modules/version'
import getters from './getters'
Vue.use(Vuex)
@@ -33,7 +34,8 @@ const store = new Vuex.Store({
lang,
site,
setting,
// 百度统计
version,
// 统计
stats
},
getters

View File

@@ -0,0 +1,21 @@
const state = {
version: ''
}
const getters = {}
const mutations = {
SET_VERSION: (state, value) => {
state.version = value
}
}
const actions = {}
export default {
namespaced: true,
state,
getters,
mutations,
actions
}

View File

@@ -49,7 +49,7 @@ export default {
return !this.sidebar.opened
},
version () {
return window.sessionStorage.getItem('v')
return this.$store.state.version.version || window.sessionStorage.getItem('v')
}
},
data () {