蓝桥杯web:第十题【功能实现】购物车

在代码中需要修改的部分有相关提示,请仔细阅读,然后完善 index.html 中的 js 部分代码,请求数据,并让数据正确显示到页面上,完成后效果如下:

json数据

[
	{
		"id": 6,
		"name": "橘子",
		"price": 3.9,
		"num": 1,
		"img": "./images/img1.jpg"
	},
	{
		"id": 7,
		"name": "车厘子",
		"price": 138.8,
		"num": 2,
		"img": "./images/img2.jpg"
	},
	{
		"id": 7,
		"name": "草莓",
		"price": 28.5,
		"num": 3,
		"img": "./images/img3.jpg"
	},
	{
		"id": 7,
		"name": "菠萝",
		"price": 9.8,
		"num": 4,
		"img": "./images/img4.jpg"
	}
]

完善index.html代码,将数据渲染到页面上

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>购物车</title>
	<script src="./js/vue.js"></script>
	<script src="./js/axios.js"></script>
	<link rel="stylesheet" href="./css/element-ui.css">
	<link rel="stylesheet" href="./css/index.css">
</head>

<body>
	<div class="container" id="app" >
		<h4>购物车</h4>
		<!-- 购物车列表 -->
		<div  v-for="(item,index) in carlist">
			<el-card class="box-card">
				<!-- 商品图片 -->
				<img :src="item.img">
				<div>

					<span>
						{{item.name}}<!-- 商品名称 -->
					</span>
					<div class="bottom clearfix">
						<el-button type="text" class="button">+</el-button>
						<el-button type="text" class="button">
							<!-- 商品数量 -->
							{{item.num}}
						</el-button>
						<el-button type="text" class="button">-</el-button>
					</div>
				</div>
			</el-card>
		</div>
	</div>
	</div>

	<!-- 引入组件库 -->
	<script src="./js/element-ui.js"></script>
	<script>
		new Vue({
			el: "#app",
			data: {
				carlist: [] //购物车列表
			},
			created() {
				// 在这里使用axios 发送请求
				var that=this;
				axios.get("./carList.json").then(function(response){
					console.log(response.data);
					that.carlist=response.data
				})
			},
		})


	</script>
</body>




</html>

 考察点:axios请求数据,vue的基本属性

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值