>  기사  >  웹 프론트엔드  >  크로스 도메인 액시스를 구현하는 세 가지 방법은 무엇입니까?

크로스 도메인 액시스를 구현하는 세 가지 방법은 무엇입니까?

coldplay.xixi
coldplay.xixi원래의
2020-08-20 13:15:1722203검색

교차 도메인 axios를 구현하는 세 가지 방법: 1. [mian.js]에서 axios를 참조합니다. 코드는 [Vue.prototype.$axios = axios]입니다. 2. 페이지에서 axios를 참조하면 코드는 [this. $ axios.post('/api/].

크로스 도메인 액시스를 구현하는 세 가지 방법은 무엇입니까?

Axios가 도메인 간을 달성하는 세 가지 방법:

1. mian.js는 axios

import axios from 'axios'
 
Vue.prototype.$axios = axios

를 참조합니다. 2. config/의 dev에 추가하세요. index.js 다음 코드는

proxyTable: {
 
    '/api': {
 
         target: 'http://127.0.0.1/hyhy/',//设置你调用的接口域名和端口号 别忘了加http
 
         changeOrigin: true,
 
         pathRewrite: {
 
              '^/api': '/'//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调             用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
 
        }
 
    }
 
}

3입니다. 페이지의 인용문

this.$axios.post('/api/userlogin/login', Qs.stringify({ username: this.username, password: this.password }))
 
.then((response) => {
 
    console.log(response)
 
})
 
.catch((response) => {
 
    console.log(response)
 
})

관련 학습 권장사항: js 비디오 튜토리얼

위 내용은 크로스 도메인 액시스를 구현하는 세 가지 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.