首先使用vue-resource,需要安装 : https://blog.csdn.net/qq_36947128/article/details/72832977

下面我写的一个例子:

网络请求应该作为全局的,所以在项目的man.js中导入并使用它:

import VueResource  from 'vue-resource'

Vue.use(VueResource);

然后就是在自己写的组件中使用了,怎么写组件请看我前面的文章: https://www.cnblogs.com/fps2tao/p/9377652.html

我这里在我的listBox.vue中使用:

测试的接口地址: http://jsonplaceholder.typicode.com/users

<template>
<div class="listBox">listBox222
<li v-for="user in users">{{user.name}}</li>
</div>
</template> <script> export default {
name: "listBox",
data:function(){
return {'users':'test-ttt'}
},
created:function(){
this.$http.get("http://jsonplaceholder.typicode.com/users").then(
(data)=>{ this.users = data.body;//可以打印,数据在body里面
})
}
}
</script> <style scoped> </style>

结果:

最新文章

  1. C#程序以管理员权限运行
  2. 网站登录后会话无法保存。php环境
  3. Android 手机自动化测试工具有哪几种?
  4. linux 查看服务器性能常用命令
  5. linearlist和linkedlist的区别 待整理
  6. 传说中的WCF(4):发送和接收SOAP头
  7. Combine Two Tables
  8. Sizzle 源码分析 (二)
  9. Count on a tree SPOJ - COT (主席树,LCA)
  10. SqlServer xml类型 查询及操作
  11. “新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛(D题,贪心+栈)
  12. C#中Key事件
  13. Nvme固体硬盘Intel750,SM961分别使用一段时间以后对比
  14. LeetCode - Subtree of Another Tree
  15. C++中 top()与pop()
  16. 设计模式——适配器模式(type-c转3.5mm耳机口)
  17. (转)【Unity Shaders】Vertex Magic —— 访问顶点颜色
  18. 同时启动多个Tomcat服务器
  19. 图论&amp;搜索:K短路-启发式搜索
  20. Ubantu apt source 国内

热门文章

  1. g++ 链接*.a静态库 方法
  2. Ext表格控件
  3. s:iterator循环输出数字
  4. Android之MVC模式
  5. poj 3258 River Hopscotch 题解
  6. iOS:CoreData数据库的使用一(创建单个数据库表)
  7. 【Linux】Dockerfile,ubuntu默认shell不是bash?RUN source命令报错!
  8. TextView子类的常用属性
  9. 【Project Euler 1】Multiples of 3 and 5
  10. ganglia组播和单播