05.vue-resource的基本使用
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./lib/vue.js"></script>
<!-- 注意:vue-resource依赖于vue,所以在引用时要注意顺序 -->
<!-- this.$http -->
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script> </head> <body>
<div id="app">
<input type="button" value="get" @click="getInfo">
<input type="button" value="post" @click="postInfo">
<input type="button" value="jsonp" @click="jsonpInfo">
</div>
</body>
<script>
new Vue({
el: '#app',
data: { },
methods: {
getInfo() {
//通过.then来是指成功的回调函数
this.$http.get('https://cn.vuejs.org').then(function(result) {
//通过result.body拿到服务器返回成功的数据
//console.log(result.body);
})
},
postInfo() { //发起post请求
//手动发起的post请求,默认没有表单格式,所以有的服务器处理不了
//通过post方法的第三个参数,设置提交内容的类型为普通表单数据格式
this.$http.post('http://vue-studyit.io/api/post', {}, {
emulateJSON: true
}).then(function(result) {
//console.log(result.body)
})
},
jsonpInfo() { //发起jsonp 请求
this.$http.jsonp('http://vue-studyit.io/api/jsonp').then(result => {
console.log(result.body)
})
}
}
})
</script> </html>
05.vue-resource的基本使用的更多相关文章
- vue resource 携带cookie请求 vue cookie 跨域
vue resource 携带cookie请求 vue cookie 跨域 1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm instal ...
- Vue Resource root options not used?
I specify a root options in my Vue-Resource in my main.js file, but when I do the request, it does n ...
- vue -resource 文件提交提示process,或者拦截处理
this.$http.post('url',fd||data,{emulateJSON:true}).then(fn(res){},fn(res){}) process成功案例 _self.$http ...
- vue resource 携带cookie请求 vue cookie 跨域(六)
1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm install vue-resource --save 在主方法添加 过滤 Vue.h ...
- vue resource patch方法的传递数据 form data 为 [object Object]
今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...
- 05.VUE学习之表达式
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 05 vue项目01-组件关系、bootstrap
1.django后端项目 1.项目预期 配置前端静态资源 页面展示 2.django项目代码 主url from django.contrib import admin from ...
- 05 Vue项目搭建
Vue-CLI 项目搭建 1.环境搭建 安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ 安装cnpm npm install -g cnpm --regi ...
- 05 . Vue前端交互,fetch,axios,以asyncawait方式调用接口使用及案例
目标 /* 1. 说出什么是前后端交互模式 2. 说出Promise的相关概念和用法 3. 使用fetch进行接口调用 4. 使用axios进行接口调用 5. 使用asynnc/await方式调用接口 ...
- Vue.js——使用$.ajax和vue-resource实现OAuth的注册、登录、注销和API调用
概述 上一篇我们介绍了如何使用vue resource处理HTTP请求,结合服务端的REST API,就能够很容易地构建一个增删查改应用.这个应用始终遗留了一个问题,Web App在访问REST AP ...
随机推荐
- Java基础学习(2)
Java基础学习(二) 面向对象 对象:客观存在的事物 面向对象:人具体关注的事物的某些信息 类:是模子,确定对象会拥有的特征(属性)和行为(方法) 对象的属性:对象具有的各种特征 对象的方法:对象能 ...
- rest_framework框架的认证、权限
REST_FRAMEWORK = { "DEFAULT_AUTHENTICATION_CLASSES": ["app01.utils.TokenAuth", ] ...
- 【转】linux 查看哪些进程用了swap
转自:http://blog.csdn.net/xiangliangyu/article/details/8213127 如果系统的物理内存用光了,则会用到swap.系统就会跑得很慢,但仍能运行;如果 ...
- Redis 启动警告解决
Redis 启动警告解决[转] [root@centos224]# service redisd start 21985:M 24 Nov 04:07:20.376 * Increased maxim ...
- win10系统迁移到新的硬盘
笔记本换个硬盘,但是程序员在开发中需要各种环境配置,不想重装系统,重新系统容易,但是装各种软件和配各种环境就比较麻烦了,所以笔记本加固态硬盘,可以不用重装,直接"系统迁移"到新的硬 ...
- vue路由传参并跳转页面
在vue项目中参数的传递可以使用本地缓存或者Vuex,那么vue能不能像小程序一样路由传参呢,显然是可以的而且非常简单 方式一:query传参 //传参 go(){ that.$router.push ...
- php开发常用技巧总结
1.[本地开启xdebug导致执行时间超max_execution_time产生的问题处理方法]xdebug开启,会导php执行速度慢,超max_execution_time,这种情况下有必要合理设置 ...
- D2. Remove the Substring (hard version)
D2. Remove the Substring (hard version) 给字符串s,t,保证t为s的子序列,求s删掉最长多长的子串,满足t仍为s的子序列 记录t中每个字母在s中出现的最右的位置 ...
- Swift hash & hashValue区别
最后更新: 2017-07-22 在Swift标准库中,NSObjectProtocol协议 public var hash: Int { get } Equatable协议: extension N ...
- 笔记本连接树莓派3b(不需要屏幕)
一.网线直连 工具:笔记本,网线,树莓派 软件:putty 过程: 将系统烧录进SD卡后,在root里添加一个名字为“ssh”的空白文件(不需后缀名)来开启ssh服务,SD卡里的cmdline.txt ...