I'm currently utilizing version 0.33.1 of @nuxtjs/composition-api
along with Nuxt 2. Here's a snippet from my component:
import { defineComponent, useContext, useRoute, watch } from '@nuxtjs/composition-api';
export default defineComponent({
setup () {
const route = useRoute();
// Other code...
watch(() => route.value.query, () => {
const { $axios } = useContext();
});
// Other code...
}
});
My objective is to take action whenever the route.value.query
undergoes a change. However, I keep encountering this error message:
Error: This must be called within a setup function.
at useContext (index.mjs?9a99:220:1)
at eval (search.vue?9447:34:1)
at invokeWithErrorHandling (vue.common.dev.js?4650:3634:1)
at call (vue.common.dev.js?4650:3271:1)
at watcher.run (vue.common.dev.js?4650:3375:1)
at flushSchedulerQueue (vue.common.dev.js?4650:3140:1)
at Array.eval (vue.common.dev.js?4650:3760:1)
at flushCallbacks (vue.common.dev.js?4650:3682:1)
Am I overlooking something here? Is there a way for me to utilize useContext()
within the watch()
callback? Or is this simply not feasible?