詳解vue中配置代理(解決跨域請求)
更新時間:2023年08月03日 10:52:12 作者:林代碼er
這篇文章主要為大家詳細介紹了vue如何通過配置代理來解決跨域請求的問題,文中的示例代碼講解詳細,對我們深入學習vue有一定的幫助,感興趣的小伙伴可以跟隨小編一起學習一下
app.vue
<template>
<div>
<button @click="getStudents">獲取學生信息</button>
<button @click="getCars">獲取汽車信息</button>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: 'App',
methods:{
getStudents(){
axios.get('http://localhost:8080/liners/students').then(
response => {
console.log('請求成功了',response.data)
},
error=>{
console.log('請求失敗了',error.message)
}
)
},
getCars(){
axios.get('http://localhost:8080/linerc/cars').then(
response => {
console.log('請求成功了',response.data)
},
error => {
console.log('請求失敗了',error.message)
}
)
}
}
}
</script>Vue腳手架配置代理

vue.config.js
module.exports = {
pages:{
index:{
entry:'src/main.js'
}
},
lintOnSave:false,//關閉語法檢查
//開啟代理服務器(方式1)
/* devServer:{
proxy:'http://localhost:5000'
},*/
}
vue.config.js
module.exports = {
pages:{
index:{
entry:'src/main.js'
}
},
lintOnSave:false,//關閉語法檢查
//開啟代理服務器(方式1)
/* devServer:{
proxy:'http://localhost:5000'
},*/
}
到此這篇關于詳解vue中配置代理(解決跨域請求)的文章就介紹到這了,更多相關vue配置代理內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue+springboot實現(xiàn)項目的CORS跨域請求
這篇文章主要介紹了vue+springboot實現(xiàn)項目的CORS跨域請求,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
Vue+Flask實現(xiàn)簡單的登錄驗證跳轉的示例代碼
本篇文章主要介紹了Vue+Flask實現(xiàn)簡單的登錄驗證跳轉的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01

