vue2.7.16组合式API的watch监听不倒$route的变化。 #11108
Unanswered
qew4
asked this question in
Help/Questions
Replies: 3 comments 7 replies
-
<script lang="ts" setup>
import { watch } from 'vue';
import { useRoute } from 'vue-router';
const route = useRoute();
watch(
() => route.query,
(query) => {
console.log(query);
},
{ immediate: true },
);
</script> |
Beta Was this translation helpful? Give feedback.
6 replies
-
See #9512 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
-
你试试 import { useRoute } from 'vue-router/composables' 能不能解决 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
vue2.7.16组合式API的watch监听不倒$route的变化。我主要是想在query发生变化后重新赋值给常量。但是不生效。
watch(()=>$route.query,(val)=>{ console.log(val) filterId.value = val.id },{ deep:true, immediate:true })
$route的来路:
import {useRoute} from "@/utils"; const $route = useRoute();
utils中的useRoute:
export function useStore() { const { proxy } = getCurrentInstance() const store = proxy.$store return store }
请问有人碰到这个问题吗?
Beta Was this translation helpful? Give feedback.
All reactions