打开写的服务器(http://localhost:5000/students)正常
vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave: false,//关闭语法检查
devServer: {
proxy: 'http://localhost:5000'
}
})
App.vue
<template>
<div>
<button @click="getStudents">获取学生信息</button>
</div>
</template>
<script>
import axios from 'axios'
export default {
name:'App',
methods: {
getStudents(){
axios.get('http://localhost:8080/students').then(
response => {
console.log('请求成功了',response.data)
},
error => {
console.log('请求失败了',error.message)
}
)
},
},
}
</script>
还是显示跨域的问题
点击按钮后正常获取get请的内容
将 app.vue中的localhost改为自己打开浏览器的地址栏显示的地址