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