我在watch和vue router的文档中有几乎相同的示例用于组合 API。但console.log即使route.params.gameId在模板中正确显示,也永远不会被触发
<script setup>
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useStore } from 'vuex'
const store = useStore()
const route = useRoute()
watch(
() => route.params.gameId,
async newId => {
console.log("watch"+newId)
}
)
</script>
<template>
<div>
{{route.params.gameId}}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我还尝试使 watch 函数成为非异步的,但它没有改变任何东西,稍后我将需要它来获取 api,所以它应该是异步的。
vue.js vue-router vuejs3 vue-composition-api vue-script-setup