Vue中发送网络请求


前言

学习vue中发送网络请求


提示:以下是本篇文章正文内容,下面案例可供参考

一.vue中发送网络请求

1.下载npm 包管理器

https://nodejs.org/en/

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
安装完毕,打开cmd,输入npm -v 检查npm 是否安装完毕【见如下界面说明npm安装完毕】
在这里插入图片描述

2 .安装json-server 工具

   npm i  -g json-server

在这里插入图片描述

3.创建db.json

{
	"brands":[
		{
			"id":1,
			"name":"TCL",
			"create_time":"Mon Oct 26 2020 20:49:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":2,
			"name":"Apple",
			"create_time":"Mon Oct 26 2020 17:49:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":3,
			"name":"HuaWei",
			"create_time":"Mon Oct 26 2020 18:49:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":4,
			"name":"百度",
			"create_time":"Mon Oct 26 2020 10:49:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":5,
			"name":"腾讯",
			"create_time":"Mon Oct 26 2020 18:42:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":6,
			"name":"阿里巴巴",
			"create_time":"Mon Oct 26 2020 16:49:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":7,
			"name":"大华",
			"create_time":"Mon Oct 26 2020 14:22:06 GMT+0800 (中国标准时间)"
		},
		{
			"id":8,
			"name":"中兴",
			"create_time":"Mon Oct 26 2020 18:23:06 GMT+0800 (中国标准时间)"
		}
	]
}

4. 启动json-server

json-server --watch --port 30001 db.json

在这里插入图片描述
请求访问
在这里插入图片描述

5.json-server restful接口使用规则

https://github.com/typicode/json-server
在这里插入图片描述

6.见解高效的http库-axios

npm安装

  npm install axios

cdn引入

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	</body>
</html>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
	axios.get("http://127.0.0.1:30001/brands/1").then(result =>{
		console.log(result.data);
	}).catch(err => {
		console.log(ee);
	})
</script>

在这里插入图片描述


总结

学习vue中发送网络请求

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值