<!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>vue=resource基本使用</title>
<script src="./lib/jquery2.1.4.min.js"></script>
<script src="./lib/Vue2.5.17.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.min.js"></script>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/css/bootstrap.css">
<!-- Github : https://github.com/pagekit/vue-resource -->
<!-- 除了vue-resource之外,还可以使用 axios 的第三方包实现数据的请求 -->
<!-- 使用方式 this.$http.get || post || jsonp -->
</head>
<style>
</style> <body>
<div id="app">
<input type="button" class="btn btn-primary" value="get请求" @click="getInfo">
<input type="button" class="btn btn-primary" value="post请求" @click="postInfo">
<input type="button" class="btn btn-primary" value="jsonp请求" @click="jsonInfo">
</div> <script>
var vm = new Vue({
el: '#app',
data: {},
methods: {
getInfo() {//发起get请求
//当发起get请求之后,通过.then来设置,接收返回结果res是个对象。
//接口地址已失效
this.$http.get("http://vue.studyit.io/api/getlunbo").then(function(res){
console.log(res);
})
},
postInfo(){
//第一个传的对象是数据,第二个传的对象是配置选项
this.$http.post("http://vue.studyit.io/api/getlunbo",{},{emulateJSON:true}).then(res => {
console.log(res);
})
},
jsonInfo(){//发起jsonp请求
this.$http.post("http://vue.studyit.io/api/jsonp").then(res => {
console.log(res);
})
}
},
})
</script>
</body> </html>

Vue系列之 => 通过vue-resource发起ajax请求的更多相关文章

  1. vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询

    vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询 基于element Transfer http://element-cn.eleme.io/#/zh-CN/comp ...

  2. Vue系列(二):发送Ajax、JSONP请求、Vue生命周期及实例属性和方法、自定义指令与过渡

    上一篇:Vue系列(一):简介.起步.常用指令.事件和属性.模板.过滤器 一. 发送AJAX请求 1. 简介 vue本身不支持发送AJAX请求,需要使用vue-resource.axios等插件实现 ...

  3. 前端vue系列-起始篇 vue的基本认知

    hi,大家伙,我是佛系大大,很高兴与你们一起沟通,学习,进步. 很久不更新博客了,现在回来再写博客,尽然是有些怀念的感觉,幸福的感觉.因为写博客,内心会很宁静,沉浸在自己的世界中,是很幸福的一件事.当 ...

  4. VUE系列一:VUE入门:搭建脚手架CLI(新建自己的一个VUE项目)

    一.VUE脚手架介绍 官方说明:Vue 提供了一个官方的 CLI,为单页面应用快速搭建 (SPA) 繁杂的脚手架.它为现代前端工作流提供了 batteries-included 的构建设置.只需要几分 ...

  5. JQuery发起ajax请求,并在页面动态的添加元素

    页面html代码: <li> <div class="coll-tit"><span class="coll-icon">& ...

  6. vue使用resource发送ajax请求

    <script type="text/javascript"> new Vue({ el:'#app', created:function(){ var url=&qu ...

  7. VUE系列二:vue基础

    一.组件嵌套 1. 新建一个组件Users.vue <template> <div class="users"> <ul> <li v-f ...

  8. Ecstore中如何调用发起Ajax请求

    Ecstore的JS框架使用了mootools,所以ajax调用也使用mootools中的Request组件. 语法: var myRequest = new Request([options]); ...

  9. Vue系列(一):简介、起步、常用指令、事件和属性、模板、过滤器

    一. Vue.js简介 1. Vue.js是什么 Vue.js也称为Vue,读音/vju:/,类似view,错误读音v-u-e 是一个轻量级MVVM(Model-View-ViewModel)框架,和 ...

随机推荐

  1. LeetCode 944 Delete Columns to Make Sorted 解题报告

    题目要求 We are given an array A of N lowercase letter strings, all of the same length. Now, we may choo ...

  2. 原生js获取到页面上所有的checkbox

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...

  3. IDEA集成的 Thrift 插件进行 thrift 编译

    IDEA集成的 Thrift 插件进行 thrift 编译 注意 1.thrift文件要放在source目录,才有compile选项 2.generator list的output path不用加包名 ...

  4. MySql left join 多表连接查询优化语句

    先过滤条件然后再根据表连接 同时在表中建立相关查询字段的索引这样在大数据多表联合查询的情况下速度相当快 创建索引: create index ix_register_year ON dbo.selec ...

  5. 解决因为Telnet没有启动导致FTP无法连接的问题

    今天ytkah在其他电脑上想用ftp传点东西发现居然连接不上,查看了一下服务器安全组规则里的端口,也没有相关屏蔽.问了一下运维,他说可能是Telnet没有开启.就试着去看看有没问题.打开 控制面板 - ...

  6. abap调用代码块

    1:abap 调用代码块. *&---------------------------------------------------------------------* *& Re ...

  7. Mac charles 抓取https请求,安装证书后还是显示unknown

    https://blog.csdn.net/qq_23114525/article/details/81460840 1. 配置证书 2. 设置钥匙串信任 3. 设置手机代理 端口号需要对应设置的端口 ...

  8. spark on yarn任务提交缓慢解决

    1.为什么要让运行时Jar可以从yarn端访问spark2以后,原有lib目录下的大JAR包被分散成多个小JAR包,原来的spark-assembly-*.jar已经不存在 每一次我们运行的时候,如果 ...

  9. yum 安装报错 File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:

    原因: 这是因为yum采用python作为命令解释器,这可以从/usr/bin/yum文件中第一行#!/usr/bin/python发现.而python版本之间兼容性不太好,使得2.X版本与3.0版本 ...

  10. 17-Python3 循环语句

    2018-11-21 18:23:56 print('pass语句') for letter in 'Runoob': if letter=='o': pass else: print(letter) ...