1. 安装vue-resource 

npm install vue-resource --save

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

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

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

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

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);
  });

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

 

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-11-10
  • 2021-11-09
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案