• Welcome to the eight blog of that year. I am very glad to meet you at the right age.
  • The little buddy who has logged on QQ due to the theme shows the default head in the comments. Please go to the personal center to upload the avatar again.

remember Vue.js A cross domain request method using Axios

Code Notes Barben 1 years ago (2019-05-19) 851 browse 1 comments

Today is another day of fishing at home. Knock BUG Write an online translation function.

And then he took it down. Baidu translate open platform technical document In the example interface address, try and ask for normal request.

It's really sweet to request with Axios.

 Axios.get () Http://api.fanyi.baidu.com/api/trans/vip/translate? Q=apple&from=en&to=zh&appid=2015063000000001&salt=1435660288&sign=f89f9594663708c1605f3d736d01d2d4 (
.then) ((response) = { Console.log (response); {}} 
.catch ((error) = {}. Console.log (error);

This story tells us a more fun request. No Access-Control-Allow-Origin header is present on the requested resource I will never forget to hit your head!

Obviously, this is due to the failure of requests across domains.

Resolving cross domain requests

1. open config/ Index.js file
2. in Index.js The following code is found

 Module.exports = {
dev: {
proxyTable: {}

3. modify the proxyTable in the code as shown below.

 ProxyTable: {
'/api': {
target:' Https://www.barben.cn / / write the domain name and port to call the interface. Remember to add http. 
changeOrigin: true, 
pathRewrite: {
'^/api': / / / here is understood to replace /api in target address, calling the interface directly with /api instead. For example, I want to call. Https://www.barben.cn/request/ts Interface, write /api/request/ts directly. I am very sorry.

4. restart the whole project.

After modifying proxyTable, the cross domain request is successfully solved.



Eight this year's blog, we've been there.
If the author does not indicate the original article, please indicate the link and source.
remember Vue.js A cross domain request method using Axios - Https://www.barben.cn/code/482.html
Love ( Ten )
Publish my comments
Cancel comment
Expression Map Thickening Delete line Centered Italics

In the eight year commentary, you need to bring your nickname and mailbox.

  • Nickname (required)
  • Mailbox (required)
  • Website
Successfully captured. One Only rare elves
  1. Big guy, I want to learn the special effects of canvas, that is, there is a sister next to the website. It will follow the mouse and click on her to do all kinds of actions. Can the big guy write a tutorial? Thank you very much for bringing me a breakthrough in technology.
    Front-end small white Summer 2019-12-03 17:52. Reply