Request Wechat third-party interface access_token in Vue to report a cross-domain error. Why?

clipboard.png

shows the cross-domain problem after the call, but it can be opened in the browser address bar and the access_token, can be obtained, but the request in Vue always shows the cross-domain problem. What is the cause and how to solve it


if the server has been configured to allow cross-domain, you can try this method:

axios({
    method: '$method',
    url: '$url',
    data:{
        param:'$params'
    },
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Access-Control-Allow-Origin': *,
    }
}).then(function(res){
    return res.data;
});

give it a try?

as mentioned above, this kind of business with excessive privacy is best carried out on the server side, and the client side can just take the response.


Let the backend get


but it can be opened in the browser address bar and access_token can be obtained

there is no cross-domain when you open it directly. And Wechat API needs to initiate a request in the background, otherwise your appid,secret may leak


Cross-domain allows your backend to retrieve the request

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-1b3b747-2c2a0.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-1b3b747-2c2a0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?