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目录下创建

axios 请求数据 + 配置代理_ios

 

 

module.exports={
pages:{
index:{
// 入口
entry:'src/main.js',
},
},
lintOneSave:false,//关闭语法检查
// 开启代理服务器
devServer:{
Proxy:'http//localhost:5000'
}
}

需要重启项目

 

axios 请求数据 + 配置代理_ios_02