this mainly depends on the company's process. In general, the data structure of the interface is better understood by the server. The server usually simulates the data to the frontend rather than the frontend itself.
but set up the agent to read json data during development and request the interface between the formal environment and the test environment during formal testing. While the url used during development is consistent
< hr >
// dev.env.js
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
host: '0.0.0.0',
AXIOS_BASR_URL: '""',
NUM: '0'
})
you can read this chapter on vue-cli 2.9.3 development mode variables and production mode variables.
specify the environment variable, and you can judge the status in production mode or development mode.
the separation of foreground and background does not mean that the foreground and background are completely independent and then finally merged, but in mode. In the development phase, the background data read by the foreground is obtained according to the interface provided to you by the background personnel (, there will be an accident when the foreground forges the data), and then you judge whether the operation is successful according to the returned status code.
what is common is:
- 200 ok
- 404 not found
- 500The background code is abnormal. You should ask the comrade in the background about the situation
in addition, the value provided by the background is not necessarily a json string (so you can't forge it). You need to communicate before the project is developed. If he wants to provide the value that is put into the collection or array, then you have to convert it.
here is a simple get request for axios:
//
findAllClass:(context,id)=>{
return new Promise((resolve,reject)=>{
axios.get('url',{params:{id}}).then(({data})=>{
if(data.status==200){
resolve(data.data);
}else{
reject(data);
}
}).catch((error)=>{
reject(error);
});
});
},
the specific situation of each company is different. Our company decides the format and content of the interface at the beginning of the development. The background development engineer will send the interface document to the front end in advance, and then generate fixed data in the background interface (the format is consistent with the final development data), so that the front-end engineer can directly call the background interface for development and testing. Wait for the background engineer to complete the interface development before joint debugging.
about the configuration of the vue development environment and production environment, you can refer to an article I wrote: https://codeshelper.com/a/11.
you can take a look at this to get help https://github.com/azl3979858.
.