最近学习了Vue,发现了Vue 功能的强大,在此做了一个小案例:实现商品添加到购物车的功能。
大家可以看一下演示图:
这里使用的知识点包括:vue基本常用指令的使用、组件化、父子组件之间的通讯、数据监听watch和computed等
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>商品添加到购物车的案例</title>
<script src="js/vue.js"></script>
<style type="text/css">
table {
border-collapse: collapse;
width: 50%;
height: 160px;
}
td {
text-align: center;
}
</style>
</head>
<body>
<div id="app"></div>
</body>
<script>
//购物车组件
var Chat = {
props: ['chatarr'],
template: `
<div align="center">
<table border="1">
<tr>
<th colspan="4">购物车</th>