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


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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM