vue-resource实现get,post,jsonp请求
来源:互联网 发布:打印文件软件 编辑:程序博客网 时间:2024/06/04 18:22
一、vue-resource概述
1、 使用:引入vue-resource
<script src="js/vue.js"></script><script src="js/vue-resource.js"></script>
2、支持的HTTP方法
vue-resource的请求API是按照REST风格设计的,它提供了7种请求API:
get(url, [options])head(url, [options])delete(url, [options])jsonp(url, [options])post(url, [body], [options])put(url, [body], [options])patch(url, [body], [options])
3、options对象
发送请求时的options选项对象包含以下属性:
二、代码展示
<!doctype html><html> <head> <meta charset="UTF-8"> <title></title> <script src="node_modules/vue/dist/vue.min.js" type="text/javascript" charset="utf-8"></script> <script src="node_modules/vue-resource/dist/vue-resource.min.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div id="app"> <button @click = "get">get请求</button> <button @click = "post">post请求</button> <button @click = "jsonp">jsonp请求</button> <p>{{message}}</p> </div> <script type="text/javascript"> //Vue.http.options.emulateJSON = true; new Vue({ el:"#app", data:{ message:"" }, methods:{ get:function(){ this.$http.get("package.json",{ params:{ user:"123" }, headers:{ token:"1234" } }).then(function(res){ this.message = res.data; },function(err){ this.message = err; }) }, post:function(){ this.$http.post("package.json",{ user:"1234" },{ headers:{ token:"1234" } }).then(function(res){ this.message = res.data; },function(err){ this.message = err; }) }, jsonp:function(){ this.$http.jsonp("http://www.imooc.com/course/ajaxskillcourse?cid=796",{ params:{ user:"123" }, headers:{ token:"1234" } }).then(function(res){ this.message = res.data; },function(err){ this.message = err; }) } } }) </script> </body></html>
阅读全文
0 0
- vue-resource实现get,post,jsonp请求
- vue-resource、Vue中response的get、post和jsonp请求例子
- Vue resource中的GET与POST请求
- Vue resource中的GET与POST请求
- vue+vue-resource post请求
- vue-resource post请求的坑
- ajax 跨域请求 vue-resource jsonp跨域
- Vue mock & vue-resource & JSONP
- Vue-post和get请求实例
- vue中get和post请求
- vue-resource 1.2 jsonp用法(实现百度搜索功能)
- java实现post,get请求
- java实现GET/POST请求
- HttpClientUtil实现post、get请求
- Jsonp请求只能是GET不能是POST
- vue-resource POST请求 报400错误解决方案
- vue.js(vue-resource) ---jsonp跨域
- JSONP跨域GET请求
- hdu 1025 Constructing Roads In JGShining's Kingdom LIS最长上升序列
- Python实现Adaboost(decisiontree)
- 可拉伸的tabview头部视图
- 斐波那契数列
- Java NIO浅析
- vue-resource实现get,post,jsonp请求
- 商务旅行
- Ubuntu 切换键盘布局(colemak
- [ElasticStack系列]elasticsearch查询api
- 1013 DFS求强连通分量
- mysql存储过程
- 数组,结构体数据互相copy
- Android Studio library生成jar包和aar的方法总结
- unix网络编程起步