代码:

<div id="shoppingCart">
    <ul>
        <li>{{ name }} --- {{ price }} --- {{ count }}</li>
    </ul>
</div>
<button οnclick="reduceOne()">减少</button>

<script>
    function reduceOne() {
        Vue.set(cartData, 'count', cartData.count-1);
    }
    var cartData={
        name:"T-shirt",
        price:"$26.80",
        count:20
    };
    var cart=new Vue({
        el:"#shoppingCart",
        data:cartData
    });
</script>


页面效果:(点击一下减少,数量减少一个)



Logo

前往低代码交流专区

更多推荐