make tab work with router smoother

This commit is contained in:
Logaxn 2019-05-28 11:24:27 +08:00
parent a497744e89
commit 49e24daff3
2 changed files with 15 additions and 11 deletions

View File

@ -11,6 +11,12 @@ NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
router.beforeEach(async(to, from, next) => { router.beforeEach(async(to, from, next) => {
// skip some code, make tab work with router smoother
if (to.path === from.path) {
next()
return
}
// start progress bar // start progress bar
NProgress.start() NProgress.start()

View File

@ -26,20 +26,18 @@ export default {
{ label: 'Japan', key: 'JP' }, { label: 'Japan', key: 'JP' },
{ label: 'Eurozone', key: 'EU' } { label: 'Eurozone', key: 'EU' }
], ],
activeName: 'CN',
createdTimes: 0 createdTimes: 0
} }
}, },
watch: { computed: {
activeName(val) { activeName: {
this.$router.push(`${this.$route.path}?tab=${val}`) get() {
} return this.$route.query.tab || 'CN'
}, },
created() { set(tab) {
// init the default selected tab // this.$router.push({ query: { tab }})
const tab = this.$route.query.tab this.$router.replace({ query: { tab }})
if (tab) { }
this.activeName = tab
} }
}, },
methods: { methods: {