The front end calls the interface of the back end, and the displayed Uncaught (in promise) ReferenceError: getGoods is not defined. But we configured the request address of this interface in the backend. At the same time, the relevant interfaces are also encapsulated in the front-end axios.
Screenshot of the error:
The reason is that the encapsulated interface getGoods is not introduced into the page.
Solution: Just introduce the packaged axios in the page that needs to be used.
import { getGoods} from '@/axios/api'
The detailed process record is as follows:
1. Encapsulate the front-end request interface in axios, and call the address of the back-end deployment:
2. Configure the interface address of the front-end request in the back-end:
(My project path is: server/router/api/getGoods.js, which reminds me that what I store in this api directory is the client's request interface)
getGoods.js file:
3. Then you need to register in the app.js file:
4. Call the interface in the required page:
This is because we introduce the getGoods interface encapsulated in axios. so it was wrong
solution:
Just add the introduction directly on the basis of the above.
import { getGoods} from '@/axios/api'
A full screenshot of the usage page is: