//Introducing axios Library
Import axios from "axios"; ?
const request =axios.create({
BaseURL:' main link address'//Example: www.xxx.com/xxx.api.xxx.xxx.xx.
})
Export the default request; //Export module
You can use it src = & gtapi => to write in xxx.js
Import request from @/utils/request; //Here is the request file just written.
export const get data =()= & gt; Request ({
Method:' GET' // Write request type
Url:' This is an auxiliary connection'//Example: www.xxx.com/xxx.api.xxx.xxx.xx.
})
Finally, link the file to the corresponding file of Vue 3.
Import {getData} from @/api/xxx.
//Initialization data method for encapsulating homepage
const initIndexData = async()= & gt; {
//Deconstruct the item [data in data]
const { data } = await getHomeData()
//Judge whether the data is obtained.
if(data.status! == 200) {
//If no data is obtained, return directly.
Return;
}
//Assign the collected data to indexData.
indexData.value = data.data
}
//Call the initialization data method of the home page.
initIndexData()
Finally, put the analysis data into the specified location.