<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v-set</title>
<script src="js/vue.min.js"></script>
</head>
<body>
<h1>vue.set</h1>
<hr />
<div id="app">
<ul>
<li v-for="val in goods">
{
{val.name}} -- {
{val.num}}
</li>
</ul>
<p>总计{
{count}}件产品</p>
<button @click="clear">清空</button>
</div>
<button onclick="add()">++</button>
</body>
<script>
function add(){
sql.goods.push({name:'garden',num:'1'});
vm.count++;
}
var sql = {
count: 3,
goods: [
{name:'car',num:'2'},
{name:'house',num:'1'}
]
}
var vm = new Vue({
el: '#app',
data: sql,
met
Vue之模拟添加和清空购物车
最新推荐文章于 2023-09-16 23:11:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)