vue-cli与后台数据交互增删改查

本文介绍如何在Vue项目中解决跨域问题,通过配置proxyTable代理设置,实现前后端分离开发。同时,详细讲解使用vue-resource进行HTTP请求的方法,包括GET、POST等请求方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 安装vue-resource 

npm install vue-resource --save

2.访问后台地址,在vue中会出现跨域的问题,以下为解决方案

  在config下的index.js 中配置proxyTable代理设置

proxyTable: {
        '/api':{
            target:'http://19******:8080',
            changeOrigin:true,//允许跨域
            pathRewrite:{
                '/api':'/'
            }
        }
    },

3.地址配置完了,就可以开始访问后台,获取数据了
 我用的是vue-resource,有多种方式 get,post,json,jsonp,具体使用方法,可以查看官网

this.$http.get('url').then(response => { 
        console.log(response.body); 
      }, response => { 
        console.log(response); 
  });
this.$http.post(('url'),data ,{emulateJSON:false}).then(response => { 
       console.log(response.body);
      }, response => {
       console.log(response);
  });

 

 

转载于:https://www.cnblogs.com/Kyaya/p/10154619.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值