vue 使用 axios 時怎麼解決跨域問題

來源:互聯網
上載者:User

標籤:安裝   自己   eth   使用   ring   自己的   引入   data   method   

跨域請求是 http 請求常見的問題。

vue 架構推薦使用 axios 外掛程式請求資料, 若後台不做跨域請求的處理,那麼前台可以使用 axios 外掛程式結合 qs 外掛程式實現跨域請求。

  • 安裝外掛程式
npm install --save axiosnpm install --save qs
  • 引入外掛程式
import axios from ‘axios‘import qs from ‘qs‘
  • 在 methods 中使用
methods: {    getData() {         axios.post(url,   // url 以自己的地址為準            qs.stringify({                key: ‘‘ // 值按照需求傳入            })        ).then(res => {            console.log(res.data)        }).catch(error => {             console.log(error)        })                       }}

vue 使用 axios 時怎麼解決跨域問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.