<!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的基本使用的更多相关文章

  1. vue resource 携带cookie请求 vue cookie 跨域

    vue resource 携带cookie请求 vue cookie 跨域 1.依赖VueResource 确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm instal ...

  2. 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 ...

  3. vue -resource 文件提交提示process,或者拦截处理

    this.$http.post('url',fd||data,{emulateJSON:true}).then(fn(res){},fn(res){}) process成功案例 _self.$http ...

  4. vue resource 携带cookie请求 vue cookie 跨域(六)

    1.依赖VueResource  确保已安装vue-resource到项目中,找到当前项目,命令行输入: npm install vue-resource --save 在主方法添加 过滤 Vue.h ...

  5. vue resource patch方法的传递数据 form data 为 [object Object]

    今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...

  6. 05.VUE学习之表达式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  7. 05 vue项目01-组件关系、bootstrap

    1.django后端项目 1.项目预期 配置前端静态资源            页面展示 2.django项目代码 主url from django.contrib import admin from ...

  8. 05 Vue项目搭建

    Vue-CLI 项目搭建 1.环境搭建 安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ 安装cnpm npm install -g cnpm --regi ...

  9. 05 . Vue前端交互,fetch,axios,以asyncawait方式调用接口使用及案例

    目标 /* 1. 说出什么是前后端交互模式 2. 说出Promise的相关概念和用法 3. 使用fetch进行接口调用 4. 使用axios进行接口调用 5. 使用asynnc/await方式调用接口 ...

  10. Vue.js——使用$.ajax和vue-resource实现OAuth的注册、登录、注销和API调用

    概述 上一篇我们介绍了如何使用vue resource处理HTTP请求,结合服务端的REST API,就能够很容易地构建一个增删查改应用.这个应用始终遗留了一个问题,Web App在访问REST AP ...

随机推荐

  1. Docker守护式容器的创建和登录

    创建守护式容器 如果对于一个需要长期运行的容器来说,我们可以创建一个守护式容器(后台运行的容器). 创建(-d)并运行(-i)守护式容器命令如下(容器名称不能重复): docker run -id - ...

  2. 算法学习之二分查找算法的python实现

    ——参考自<算法图解> 我们假设需要查找的数组是有序的(从大到小或者从小到大),如果无序,可以在第四行后插入一句 my_list.sort() 完整代码如下 def binary_sear ...

  3. Spring基础07——配置集合属性

    1.集合属性 在Spring中可以通过一组内置的xml标签(例如<list>,<set>或<map>)来配置集合属性. 2.配置List集合 配置java.util ...

  4. Linux一键安装LNMP环境

    Linux一键安装LNMP环境 官方地址:https://lnmp.org/. 参考安装步骤:https://lnmp.org/install.html. 一键安装可以选择mysql版本.php版本, ...

  5. bzoj4817 & loj2001 [Sdoi2017]树点涂色 LCT + 线段树

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4817 https://loj.ac/problem/2001 题解 可以发现这个题就是 bzo ...

  6. 点击链接跳转到QQ的情况; qq交谈

    https://blog.csdn.net/qq_31856835/article/details/70225968 https://blog.csdn.net/qq_37815596/article ...

  7. Python内置函数之filter map reduce

    Python内置函数之filter map reduce 2013-06-04 Posted by yeho Python内置了一些非常有趣.有用的函数,如:filter.map.reduce,都是对 ...

  8. JDK7

    https://docs.oracle.com/javase/7/docs/index.html

  9. 【GDOI2014模拟】服务器

    前言 直到比赛最后几分钟,才发现60%数据居然是一个水dp,结果没打完. 题目 我们需要将一个文件复制到n个服务器上,这些服务器的编号为S1, S2, -, Sn. 首先,我们可以选择一些服务器,直接 ...

  10. hdu 3572 : Task Schedule (网络流)

    题目链接 题意: 有M个机器,N个任务 对第i个任务,需要在[Si,Ei]这段时间内恰有Pi天被process 每天最多有M个机器同时工作 每一天,一个任务若被process,那么它恰占用一个机器. ...