Answer the question
In order to leave comments, you need to log in
How can I access a route in an import file using the Composition API in Nuxt.js?
Hello.
I'm making a Nuxt.js application using the Composition API plugin. In the process of making requests to the API, I need a variable from the current URL.
I created a folder at the root with the name api, put a file with the contents in it:
import axios from 'axios'
import { useRoute } from '@nuxtjs/composition-api'
export const getAllItems = () => {
const route = useRoute()
const token = route.value.params.id
return axios.get(`/${token}/allItems`).then((response) => response.data)
}
getAllItems
. But as a result, the call does not occur, but an error is obtainedUncaught (in promise) Error: This must be called within a setup function.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question