在事件中使用useRoute、useRouter注意事项


可以在组合api中使用 useRoute、useRouter 如:

onMounted(() => {
    const route = useRoute()    
    route.params && console.log("param:", route.params);
})

不要像下面这样使用(会报错或警告):

const btnClick = () => {
    const route = useRoute()    
    route.params && console.log("param:", route.params);
}

改为这样用:

const router = useRouter()  

const btnClick = () => {
    router && router.push({name: 'B', params: {id: 1, name: 'jjw'}})
}