npm install axios -s
Configure the public request in the plugins
new axios
file
...
Import from the vue page
import axiosApi from "../plugins/axios";
In the asyncData
request rendering data
export default {
data() {
return {
info: []
}
},
async asyncData() {
const res = await axiosApi("getData", {
}, "post")
return {
info: res.data.top_four
}
},
}
asyncData method
The asyncData method is called every time the component is loaded.
asyncData can be called before the server or route update
. The data returned by asyncData is merged into the data method of the component. The
asyncData method is called before the component is initialized. The interior of the method cannot be this
used to reference the component. Instance object
View the source code to view the requested data