vue vue-resource 请求数据
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 请求数据的更多相关文章
- Vue之resource请求数据
导入resource文件 <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js& ...
- vue 使用 jsonp 请求数据
vue 使用 jsonp 请求数据 vue请求数据的时候,会遇到跨域问题,服务器为了保证信息的安全,对跨域请求进行拦截,因此,为了解决vue跨域请求问题,需要使用jsonp. 安装jsonp npm ...
- vue之axios请求数据本地json
写给自己的话:静态的json文件要记得放在static文件夹下,想打自己 1.下载插件 npm install axios --save 2.在main.js下引用axios import axios ...
- 聊一聊跨域,Vue向Django请求数据的一些问题
1.做前后端分离 前端使用Vue程序,后端使用Django配合rest-framework. 那么前端Vue通过API接口拿到数据会出现跨域的问题,JSONP只是在get中会用到的,所以这里使用cor ...
- Vue从接口请求数据
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- vue.js中请求数据v-for循环使用数据
1.效果图 2.cart.json { "message":"", "status":"1", "result ...
- Vue之axios请求数据
引入文件 <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"> ...
- Vue使用axios请求数据,默认post请求传参是json格式,但后台需要formData格式???
最简单的方式,post请求参数json转formData…代码如下: 使用node的 qs 模块(推荐使用) 就是这么简单,在结合element ui表单一键提交涉及到,希望遇到的同学少走弯路,加油~
- vue 对象提供的属性功能、通过axio请求数据(2)
1 Vue对象提供的属性功能 1.1 过滤器 过滤器,就是vue允许开发者自定义的文本格式化函数,可以使用在两个地方:输出内容和操作数据中. 1.1.1 使用Vue.filter()进行全局定义(全局 ...
随机推荐
- nginx unit 1.8 支持基于java servlet 的开发模型
最近unit 1.8 发布了,有两个比较大的新特性,内部请求路由,以及java servlet 容器应用的开发 内部请求路由配置参考 { "routes": [ { "m ...
- 05基于python玩转人工智能最火框架之TensorFlow基础知识
从helloworld开始 mkdir mooc # 新建一个mooc文件夹 cd mooc mkdir 1.helloworld # 新建一个helloworld文件夹 cd 1.helloworl ...
- 在sorted range上的操作(includes,set_union,set_intersection,set_difference)
includes //版本一:用operator <比较元素 template <class InputerIterator1,class InputerIterator2> boo ...
- iuplua test failure
prepared SW Download from https://sourceforge.net/projects/iup zerobrane Step Write follwiing codes ...
- django默认后台使用
1.初始化数据python manage.py migrate 2.创建超级用户python manage.py createsuperuser 然后按照提示输入就可以了 3.admin管理页面找不到 ...
- Git安装及密钥的生成(转)
1.下载Git软件:http://msysgit.github.io/ 2.安装git软件(很简单).安装成功后,在[开始]->[程序]->[git],下就会看见Git Bash和Git ...
- jdk源码剖析二: 对象内存布局、synchronized终极原理
很多人一提到锁,自然第一个想到了synchronized,但一直不懂源码实现,现特地追踪到C++层来剥开synchronized的面纱. 网上的很多描述大都不全,让人看了不够爽,看完本章,你将彻底了解 ...
- 解决“chrome adobe flash player不是最新版本”的方法
chrome地址栏输入chrome://components 更新flash后,重启chrome即可,可能需要搭梯子才能更新.
- dom响应事件
DOMsubtreeModified.DOMNodeInserted.DOMNodeRemoved.DOMAttrModified.DOMCharacterDataModified 当底层DOM结构发 ...
- 通过U盘启动vmware虚拟机
不能通过虚拟机的USB功能,而是通过硬盘映射功能实现,操作方法如下图. 1.添加硬盘,注意接口类型与启动系统的支持(XPPE不支持scsi,但10pe支持) 2.硬盘类型 3.选择U盘映射 4.按F2 ...