vuejs使用axios异步访问时用get和post的实例讲解
2018-08-09 16:48
645 查看
script中。
let data={....}; let url=xx;
方法各异:
GET:
this.$ajax.get(url,{ params:data }) .then(function (res) { console.log(res.data) }) .catch(function (error) { console.log(error) })
POST:
方法一:1.
//请求后台数据之前转换入参 let url = xx; let data = { uname:this.uname, upwd:this.upwd, pid:this.pid }; function transformRequest(data) { let ret = '' for (let it in data) { ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&' } return ret } let p = transformRequest(data) this.$ajax.post(url,p) .then(function (res) { console.log(res.data) }) .catch(function (error) { console.log(error) })
方法二:2
var qs = require('qs');
this.$ajax.get(url,qs.stringfy(data)) .then(function (res) { console.log(res.data) }) .catch(function (error) { console.log(error) })
this.$ajax是注入axios通过修改vue原型重新命名的,还是axios。
以上这篇vuejs使用axios异步访问时用get和post的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- vuejs使用axios异步访问时用get和post的方法
- ajax 实现 GET POST 异步 同步 检验mysql连接情况简单实例
- Android中使用HttpGet和HttpPost访问HTTP资源
- Android HTTP实例 使用GET方法和POST方法发送请求
- Android HTTP实例 使用GET方法和POST方法发送请求(通过Apache接口实现)
- Android中使用HttpGet和HttpPost访问HTTP资源和区别
- 使用Jquery Aajx访问WCF服务(GET、POST、PUT、DELETE)
- IOS网络篇10之NSURLConnection的使用(同步异步下载getpost)
- Android HTTP实例 使用GET方法和POST方法发送请求
- 【Servlet】Servlet应用的get、post访问及和JSP的配合使用
- Android HTTP实例 使用GET方法和POST方法发送请求
- 下面的代码示例使用 BeginGetRequestStream 方法对流实例发出异步请求。
- 使用httpclient 连接 restful webservices实例 绝对可用 get的--post
- android开发 使用HttpClient访问网络,post、get方式。注册、登陆、上传文件。
- 使用HTTP GET 和HTTP POST请求访问HTTP资源
- Android HTTP实例 使用GET方法和POST方法发送请求
- WebApi系列~实际项目中如何使用HttpClient向web api发异步Get和Post请求并且参数于具体实体类型
- 使用HTTP GET 和HTTP POST请求访问HTTP资源
- C#、Asp.net 使用 WebClient Get Post(同步、异步)
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互