【发布时间】:2020-01-19 03:49:33
【问题描述】:
当路由器更改 url 时,我无法使 v-if for element 从函数中获取布尔值。
这是我的组件标题代码
<template>
<header class="wfm-header">
<div class="wfm-header__navigations">
<div class="wfm-header__logo"></div>
</div>
<div
v-if="isPlan"
class="wfm-header-plan"
>
<div
class="wfm-header-plan__calendar"
v-if="isAuth || shopName">
<wfm-calendar />
</div>
</div>
</header>
</template>
<script lang="ts">
@Component({
components: {
wfmCalendar,
}
})
export default class wfmHeader extends Vue {
...
get isPlan() {
return this.$router.currentRoute.name === RouteNames.PLAN // it works only after Reload page
}
@Watch('$router.currentRoute.path')
changeRouter() {
console.log('plzChange') // it doesnt work
}
}
</script>
当我的路线发生变化时,我想更改 isPlan 值。我尝试使用 watch fo this.$router 并使用 beforeRouteUpdate 它没有帮助,我该怎么办?
【问题讨论】:
标签: typescript vue.js vue-router