How does vue solve cross-domain issues when using Axios

Source: Internet
Author: User

Cross-domain requests are common problems with HTTP requests.

The Vue framework recommends using the Axios plug-in Request data, if the background does not do cross-domain request processing, then the foreground can use the Axios plug-in combined with the QS plugin to achieve cross-domain requests.

  • Installing plugins
npm install --save axiosnpm install --save qs
  • Introducing Plugins
import axios from ‘axios‘import qs from ‘qs‘
  • Use in methods
methods: {    getData() {         axios.post(url,   // url 以自己的地址为准            qs.stringify({                key: ‘‘ // 值按照需求传入            })        ).then(res => {            console.log(res.data)        }).catch(error => {             console.log(error)        })                       }}

How does vue solve cross-domain issues when using Axios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.