main.js

 import Vue from 'vue';
import App from './App.vue'; /*使用vue-resource请求数据的步骤 1、需要安装vue-resource模块, 注意加上 --save npm install vue-resource --save / cnpm install vue-resource --save 2、main.js引入 vue-resource import VueResource from 'vue-resource'; 3、main.js Vue.use(VueResource); 4、在组件里面直接使用 this.$http.get(地址).then(function(){ }) */ import VueResource from 'vue-resource';
Vue.use(VueResource); new Vue({
el: '#app',
render: h => h(App)
})

Home.vue

 <template>
<!-- 所有的内容要被根节点包含起来 -->
<div id="home">
首页组件 <button @click="getData()">请求数据</button> <hr>
<br> <ul>
<li v-for="item in list"> {{item.title}}
</li>
</ul>
</div> </template> <script> /* 请求数据的模板 vue-resource 官方提供的 vue的一个插件 axios fetch-jsonp
*/ export default{
data(){
return { msg:'我是一个首页组件msg',
flag:true,
list:[]
}
},
methods:{ getData(){
//请求数据 var api='http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1'; this.$http.get(api).then((response)=>{
console.log(response); //注意this指向 this.list=response.body.result; },function(err){ console.log(err); }) }
},
mounted(){ /*生命周期函数*/ this.getData(); } } </script> <style lang="scss" scoped> /*css 局部作用域 scoped*/ h2{ color:red
} </style><template>
<!-- 所有的内容要被根节点包含起来 -->
<div id="home">
首页组件 <button @click="getData()">请求数据</button> <hr>
<br> <ul>
<li v-for="item in list"> {{item.title}}
</li>
</ul>
</div> </template> <script> /* 请求数据的模板 vue-resource 官方提供的 vue的一个插件 axios fetch-jsonp
*/ export default{
data(){
return { msg:'我是一个首页组件msg',
flag:true,
list:[]
}
},
methods:{ getData(){
//请求数据 var api='http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1'; this.$http.get(api).then((response)=>{
console.log(response); //注意this指向 this.list=response.body.result; },function(err){ console.log(err); }) }
},
mounted(){ /*生命周期函数*/ this.getData(); } } </script> <style lang="scss" scoped> /*css 局部作用域 scoped*/ h2{ color:red
} </style>

vue vue-resource 请求数据的更多相关文章

  1. Vue之resource请求数据

    导入resource文件 <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js& ...

  2. vue 使用 jsonp 请求数据

    vue 使用 jsonp 请求数据 vue请求数据的时候,会遇到跨域问题,服务器为了保证信息的安全,对跨域请求进行拦截,因此,为了解决vue跨域请求问题,需要使用jsonp. 安装jsonp npm ...

  3. vue之axios请求数据本地json

    写给自己的话:静态的json文件要记得放在static文件夹下,想打自己 1.下载插件 npm install axios --save 2.在main.js下引用axios import axios ...

  4. 聊一聊跨域,Vue向Django请求数据的一些问题

    1.做前后端分离 前端使用Vue程序,后端使用Django配合rest-framework. 那么前端Vue通过API接口拿到数据会出现跨域的问题,JSONP只是在get中会用到的,所以这里使用cor ...

  5. Vue从接口请求数据

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. vue.js中请求数据v-for循环使用数据

    1.效果图 2.cart.json { "message":"", "status":"1", "result ...

  7. Vue之axios请求数据

    引入文件 <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"> ...

  8. Vue使用axios请求数据,默认post请求传参是json格式,但后台需要formData格式???

    最简单的方式,post请求参数json转formData…代码如下: 使用node的 qs 模块(推荐使用) 就是这么简单,在结合element ui表单一键提交涉及到,希望遇到的同学少走弯路,加油~

  9. vue 对象提供的属性功能、通过axio请求数据(2)

    1 Vue对象提供的属性功能 1.1 过滤器 过滤器,就是vue允许开发者自定义的文本格式化函数,可以使用在两个地方:输出内容和操作数据中. 1.1.1 使用Vue.filter()进行全局定义(全局 ...

随机推荐

  1. 更改MySQL数据库的编码为utf8mb4

    原文:http://blog.csdn.net/woslx/article/details/49685111 utf-8编码可能2个字节.3个字节.4个字节的字符,但是MySQL的utf8编码只支持3 ...

  2. Spring通知方法错误

    错误提示,主要最后一句话    ,花了2个小时 org.springframework.beans.factory.BeanCreationException: Error creating bean ...

  3. Writing Custom Providers

    转自:https://www.terraform.io/docs/extend/writing-custom-providers.html 很详细,做为一个记录 In Terraform, a Pro ...

  4. Where关键词的用法

    where(泛型类型约束) where关键词一个最重要的用法就是在泛型的声明.定义中做出约束. 约束又分为接口约束.基类约束.构造函数约束.函数方法的约束,我们慢慢介绍. 接口约束 顾名思义,泛型参数 ...

  5. 如何优化JavaScript的构造函数

    首先看一个构造函数User,我们在调用User创建一个实例的的时候,一般都是要写上new操作符的.在这里说明一下,如果使用new关键字调用构造函数,那么构造函数里面的this总是是指向一个全新的对象( ...

  6. 判断两个IP是否处于同一子网(网段)

    如何去判断A和B两个IP是否在同一网段,假如有如下两个IP地址和子网掩码,判断他们是否是同一个网段的IP地址的方法: A IP:202.194.128.9 B IP:202.194.128.14 子网 ...

  7. HanLP中的人名识别分析详解

    在看源码之前,先看几遍论文<基于角色标注的中国人名自动识别研究> 关于命名识别的一些问题,可参考下列一些issue: u u名字识别的问题 #387 u u机构名识别错误 u u关于层叠H ...

  8. 有10 亿个 url,每个 url 大小小于 56B,要求去重,内存只给你4G

    问题:有10 亿个 url,每个 url 大小小于 56B,要求去重,内存只给你4G 思路: 1.首先将给定的url调用hash方法计算出对应的hash的value,在10亿的url中相同url必然有 ...

  9. php输出异常的检查方法

    同事在用php展示验证码时,老是无法正常显示 但是的代码在别的地方正常运行 查看了输出,是有内容的,但是就是不显示 根据经验,应该是输出的内容有混淆,就是说在输出图片内容的时候,掺杂进去额外的信息 通 ...

  10. Python数据库编程

    http://lizhenliang.blog.51cto.com/7876557/1874283 http://blog.itpub.net/22664653/list/1/?cid=86471