Home  >  Q&A  >  body text

javascript - In the vue-cli project, cross-domain problems encountered when obtaining WeChat access_token


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? ?

天蓬老师天蓬老师2639 days ago1277

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-06-30 09:59:45

    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

    reply
    0
  • 大家讲道理

    大家讲道理2017-06-30 09:59:45

    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...

    reply
    0
  • Cancelreply