axios 请求数据 + 配置代理
原创
©著作权归作者所有:来自51CTO博客作者wx62aac82759217的原创作品,请联系作者获取转载授权,否则将追究法律责任
axios请求
<template>
<div id="app">
<button @click="getStudents">获取学生信息</button>
</div>
</template>
<script>
import axios from 'axios';
export default{
name:'App',
methods:{
getStudents(){
// axios.get('http://localhost:8081/students').then(
axios.get('https://api.github.com/search/users?q=xxx').then(
response=>{
console.log('请求成功',response.data);
},
error=>{
console.log( '请求失败了',error.message);
}
)
}
}
}
</script>
<style lang="less">
</style>
代理
在项目sec目录下创建
module.exports={
pages:{
index:{
// 入口
entry:'src/main.js',
},
},
lintOneSave:false,//关闭语法检查
// 开启代理服务器
devServer:{
Proxy:'http//localhost:5000'
}
}
需要重启项目