Vue之resource请求数据

  导入resource文件

<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>

  代码块:

  1、get请求

1             var params = {
2                 locale: "zh"
3             };
4             that.$http.get('url',{params:params}).then(function (res) {
5                 console.log(res);
6             },function (err) {
7                 console.log(22222222222);
8             })        

  2、post请求:post 发送数据到后端,需要第三个参数 {emulateJSON:true}。emulateJSON 的作用: 如果Web服务器无法处理编码为 application/json 的请求,你可以启用 emulateJSON 选项。

  

1             var params = {
2                 locale: "zh"
3             };
4             that.$http.post('url',params,{emulateJSON:true}).then(function (res) {
5                 console.log(res);
6             },function (err) {
7                 console.log(22222222222);
8             })    

  API:

  

    

  

原文地址:https://www.cnblogs.com/nelsonlei/p/10528596.html