Vue接口調用問題


1、跨域問題

 

 解決方式:設置vue.config.js,如下所示:

module.exports = {
    devServer:{
        open:true,
        proxy:{
            "/text":{
                target:"接口域名",
                //changeOrigin默認是false:請求頭中host仍然是瀏覽器發送過來的host
                // 如果設置成true:發送請求頭中host會設置成target·
                changeOrigin: true,
                pathRewrite:{
                    "^/text":""
                }
            }
        }
    }
}

調用接口

 axios.get(`/text/v1/restserver/ting?method=baidu.ting.billboard.billList&type=${this.type}&size=${this.size}$offset=0&=`).then(res=>{
                console.log(res);
                this.list=res.data.song_list;
            })

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM