3.0.0-rc.9
https://github.com/rothskeller/vuewarnreport
No warning.
First, note that this is the same symptom as #1991 but not the same cause.
This is happening because of the call to watch(route, ...) which is made in client/src/pages/ID.vue. The route object has within it a reference to the component, so watching the route includes watching the component, which triggers the warning. But watching the route for changes is a typical, and indeed essential, idiom in vue-router which should not result in a console warning. I don't know whether this should be considered a vue-next bug or a vue-router-next bug, but I'm guessing the former.
watch(route) is implicitly deep: true, which traverses arbitrarily deep properties. So technically, this is expected behavior. Also, deep traversing a complex object when you only care about a few properties is wasteful.
Your use case can and should be rewritten using a computed property instead:
const id = computed(() => {
return Array.isArray(route.params.id) ? route.params.id[0] : route.params.id
})
If you must use a watcher, you should also use watchEffect and avoid deep watches:
watchEffect(() => {
id.value = Array.isArray(route.params.id) ? route.params.id[0] : route.params.id
})
@yyx990803 Your response makes sense, but permit me to note that it disagrees with the documentation for view-router-next, which explicitly calls for watching the route object. I do not know how to reconcile between two core Vue projects.
Can you point me the part of the documentation so I can take a look?
Thanks!
@yyx990803 How about setting watch(route, () => {}, { deep: false }) instead? Can I avoid deep watch as well?
watch(route)is implicitlydeep: true, which traverses arbitrarily deep properties. So technically, this is expected behavior. Also, deep traversing a complex object when you only care about a few properties is wasteful.Your use case can and should be rewritten using a computed property instead:
const id = computed(() => { return Array.isArray(route.params.id) ? route.params.id[0] : route.params.id })If you must use a watcher, you should also use
watchEffectand avoid deep watches:watchEffect(() => { id.value = Array.isArray(route.params.id) ? route.params.id[0] : route.params.id })我在vue3 中试用了 vue2 的watch: { $route(newVal, oldVal) {...}} 也会看到这个报警, 这个怎么解决?
vue3 中,这个是devtools 6.0.0 beta 2打印的,我把devtools关闭,这个waring就消失了
Close vue-devtools and the warning will disappear. This should be the problem with DevTools
Most helpful comment
watch(route)is implicitlydeep: true, which traverses arbitrarily deep properties. So technically, this is expected behavior. Also, deep traversing a complex object when you only care about a few properties is wasteful.Your use case can and should be rewritten using a computed property instead:
If you must use a watcher, you should also use
watchEffectand avoid deep watches: