<!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. Delphi2010分 AnsiChar(1个字节) 和WideChar(2个字节) 。D7都是AnsiChar。

    Delphi2010分 AnsiChar(1个字节) 和WideChar(2个字节) .D7都是AnsiChar.

  2. 转:ArcGIS API for JavaScript之图层

    参考文章地址: https://developers.arcgis.com/javascript/3/jsapi/layer-amd.html Layer |–TiledMapServiceLayer ...

  3. linux新增动态库后可执行程序找不到的问题

    linux为了加快程式执行时对共享库的定位速度,避免使用搜索路径查找共享库的低效率,所以是直接读取库列表文档 /etc/ld.so.cache 从中进行搜索./etc/ld.so.cache 是个非文 ...

  4. Python一个文件调用另外一个文件的方法

    from common.Log import MyLog as Log 写法不完善修改为 import common.Log.MyLog as Log 即可

  5. 【Python全栈-后端开发】数据库进阶

    数据库进阶 python关于mysql的API---pymysql模块 pymsql是Python中操作MySQL的模块,其使用方法和py2的MySQLdb几乎相同. 模块安装 pip install ...

  6. MSSQL2008 部署及开启远程连接

    最近不少用户在windows2003 server 32位操作系统上安装SQL Server2008总是失败,出现大量错误.今天经过通过我反复测试安装,找出了一个便捷的安装方法,节省大家宝贵时间,具体 ...

  7. 【托业】【新托业TOEIC新题型真题】学习笔记4-题库一->P7

    --------------------------------------单词-------------------------------------- reimbursement n. 报销:偿 ...

  8. js字符串拼接

    1. 2. 3.

  9. vue.js安装问题

    1.安装:npm install --global vue-cli 2.创建项目:vue init webpack my-project npm WARN deprecated browserslis ...

  10. [ROS]一些传感器数据读取融合问题的思考

    思考问题: 1. 如何实现传感器数据的融合,或者说时间同步? 比如里程计读数和雷达数据融合? void SlamGMapping::startLiveSlam() { entropy_publishe ...