Skip to content

Commit

Permalink
響應路由參數的變化
Browse files Browse the repository at this point in the history
  • Loading branch information
malagege committed Jun 16, 2021
1 parent b1afcbb commit 9649555
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/User.vue
Expand Up @@ -2,4 +2,23 @@
<div>
User {{ $route.params.id }}
</div>
</template>
</template>

<script>
export default {
created() {
this.$watch(
() => this.$route.params,
(toParams, previousParams) => {
console.log('toParams',toParams,'previousParams',previousParams);
}
)
},
// 使用 beforeRouteUpdate 導航守衛,它也可以取消導航
async beforeRouteUpdate(to, from) {
// 對路由變化做出響應...
// this.userData = await fetchUser(to.params.id)
console.log('to',to,'from',from);
},
}
</script>

0 comments on commit 9649555

Please sign in to comment.