End mobile home page content part4 axios

vue sent ajax there are many tools available

Browser comes fetch

Now Recommended:

axios third-party modules (ajax vue in transmission)

Features:

Cross-platform data request

  • Browser xhr request
  • http server node sending request

skill:

There are five components of a home. Each component needs to send a data request. That's five requests. That performance is very low

We can then send a request to the parent-child value in the root pass member assembly.

Static knowledge throughout the project outside only direct access to the contents of this folder inside the

Role: local analog data is not submitted to the git repository (gitignore write about simulation data files can address)

Steps for usage

1. Install

npm install axios --save

2. Use

home root component introduced

Axios from Import 'Axios'    // whether the project can be introduced in the entry file

 

3.axios the url address solutions  

Reason: local analog data using a local analog url

Changes to the code before the line (modify url) is not recommended

Development environment if there is a forwarding mechanism to forward the request to the url api / index.json file to my local mock folder (that is static in the simulation data folder)

Solve: vue provides a proxy agent functionality

config file --- index.js ----  

There is a configuration file project

module.export = {
   dev: {
  proxy table: {
    '/api' : {
     target: 'http://localhost:8080',
    Pthriawrite: {
    '^/api': '/static/mock'
}      
}
}
}   
}

When the development environment to access api vue scaffolding tools will help us address replacement (conversion development environment)

Guess you like

Origin www.cnblogs.com/-constructor/p/12210825.html