Problems with front and rear interfaces of vue

I have learned a novice vue, and I have also gone through the official website. I am a bit vague about the front and back end interfaces. I don"t know if it is correct to understand this: the back end (assuming php) provides json data through .php files, and the front end reads the json data and renders the front end files through ajax. In the development stage, because the front and rear ends are developed separately, the front end needs to forge data, so can the front end directly create a json file and put it in the static folder for ajax call to read? So in the production environment, the front-end files are packaged in the dist folder. When ajax reads json data, it should not still read the fake data in the static folder. How to make ajax read the data in the real database?

Apr.05,2021

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.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e99714-47516.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e99714-47516.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?