AddSubtractButton.vue书本里的加减数量组件,自定义的指令吗,为什么要用到$emit(“update-quantity“)

<template>
  <div class="addSubtractButton">
    <input v-model="quantity" type="number">
    <div>
      <a class="add" href="javascript:;" @click="handleAdd">+</a>
      <a class="sub" @click="handleSubtract" 
        :class="{disabled: quantity === 0, actived: quantity > 0}" 
        href="javascript:;" >
        -
      </a>
    </div>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        quantity: 0
      }
    },
    name:'AddSubtractButton',
    methods: {
      handleAdd(){
        this.quantity++;
        this.$emit("update-quantity", this.quantity);
      },
      handleSubtract(){
        this.quantity--;
        this.$emit("update-quantity", this.quantity);
      }
    }
  }
</script>
<style scoped>

.addSubtractButton input{
  height: 30px;
  width: 30px;
  float: left;
  text-align: center;
} 
.addSubtractButton div{
  width: 15px;
  height: 30px;
  float: left;
  margin: 0;
  padding: 0;
  
}
.addSubtractButton a{
  text-align: center;
  vertical-align: middle;
  height: 16px;
  width: 16px;
  background-color: #ccc;
  text-decoration: none;
  border: solid 1px gray;
  display: inline-block;
  margin: 0;
  padding: 0;
  outline: none;
} 

.addSubtractButton a.add{
  margin-top: -1px;
  color: black;
}

.addSubtractButton a.sub{
  margin-top: -3px;
  border-top: none;
}

input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
  margin: 0;
}
.disabled { 
  pointer-events: none; 
  color: gray; 
  cursor: default;
}
.actived{
  color: black;
}
</style>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值