You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
<template>
|
|
<div id="app">
|
|
<router-view v-if="isRouterAlive"></router-view>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { getAllLangInfo } from "@/api/nav";
|
|
export default {
|
|
name: 'App',
|
|
provide () {
|
|
return {
|
|
reload: this.reload
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
isRouterAlive: true
|
|
}
|
|
},
|
|
created () {
|
|
// 在页面刷新时将vuex里的信息保存到localStorage里
|
|
window.addEventListener('beforeunload', () => {
|
|
localStorage.setItem('messageStore', JSON.stringify(this.$store.state))
|
|
})
|
|
// 在页面加载时读取localStorage里的状态信息
|
|
localStorage.getItem('messageStore') && this.$store.replaceState(Object.assign(this.$store.state, JSON.parse(localStorage.getItem('messageStore'))))
|
|
this.initLanguage();
|
|
},
|
|
methods: {
|
|
initLanguage(){
|
|
getAllLangInfo().then((res) => {
|
|
i18n.mergeLocaleMessage('en',res.data.en);
|
|
i18n.mergeLocaleMessage('zh', res.data.zh);
|
|
});
|
|
},
|
|
reload () {
|
|
this.isRouterAlive = false
|
|
this.$nextTick(function () {
|
|
this.isRouterAlive = true
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|