javascript - In the vue-cli project, cross-domain problems encountered when obtaining WeChat access_token
天蓬老师
天蓬老师 2017-06-30 09:57:45
0
2
1329


Figure 1 wants to get WeChat’s access_token through request


But a cross-domain request failed on the console


Requested headers


Return data is correct

Ask the master, can axios in vue use jsonp? Or how to solve this problem of getting access_token across domains? ?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
ringa_lee

access_token is not recommended to be obtained from the front desk. This needs to be obtained and processed by the background. The string you request contains the key information of your WeChat public platform. The background simulates the http request to process. The access_token can be obtained up to 2000 times a day before the valid time is up. It is valid until it expires. You need to store it in the database or somewhere to determine whether it has expired when needed. If it is not expired, use it directly. If it expires, retrieve it again

大家讲道理

Regarding using jsonp with axios, you need to install the npm package separately.

npm install jsonp --save
var jsonp = require('jsonp');

jsonp('http://www.example.com/foo', null, function (err, data) {
  if (err) {
    console.error(err.message);
  } else {
    console.log(data);
  }
});

Related links
https://github.com/mzabriskie...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template