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 ...
随机推荐
- python 变量、列表、元组、字典
python 变量.列表.元组.字典 1.python 变量赋值 2.ptython 列表 3.python 元组 4.python 字典 1. Python变量赋值 1.1变量的命名规 ...
- Linux日常之以当前时间命名文件
要求:将当前硬件信息的内容统一以一个文件的形式写入目录date中,且该文件是以“cpu_当前时间.txt”方式命名: 实现该要求主要理解三方面: (1) 显示当前硬件信息的命令:lscpu (2 ...
- vim比较文件
横向分割显示: $ vim -o filename1 filename2 纵向分割显示: $ vim -O filename1 filename2 ctl w w 切换文件
- 【前端】DOM操作
1 什么是DOM 全称 Document Object Model 文档对象模型. 一个web页面的展示,是由html标签组合成的一个页面,dom对象实际就是将html标签转换成了一个文档对象.可以通 ...
- 与Swing的初见
---------------------------参考菜鸟教程的swing课程学习-------------------- Swing 是一个为Java设计的GUI工具包. Swing是JAVA基 ...
- ESP8266-12F 中断
外部中断: 基于ESP8266的NodeMcu的数字IO的中断功能是通过attachInterrupt,detachInterrupt函数所支持的.除了D0/GPIO16,中断可以绑定到任意GPIO的 ...
- 【leetcode】Reaching Points
题目如下: A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). G ...
- IntelliJ IDEA VM options(转)
Custom IntelliJ IDEA VM options # Custom IntelliJ IDEA VM options ##################JVM模式########### ...
- js-将传来的数据排序,让(全部)这个小按钮小圈圈,始终排列在最前面
let arryDemo=[]; for(var i=0;i<data.data.length;i++){ if(data.data[i].name=='全部'){ arryDemo.push( ...
- php array_unshift()函数 语法
php array_unshift()函数 语法 作用:用于向数组插入新元素.新数组的值将被插入到数组的开头.富瑞华 语法:array_unshift(array,value1,value2,valu ...