axios 请求数据 + 配置代理

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'
    }
}
复制代码

需要重启项目

 

 

posted @   罗砂  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示