vue.js 實現購物車加減方法


  • <template>
  • <div class="coutter-wrapper">
  • <button type="button" @click="plus">+</button>
  • <button type="button">{{ result }}</button>
  • <button type="button" @click="minus">-</button>
  • </div>
  • </template>
  • <script>
  • export default {
  • data() {
  • return {
  • result: 0,
  • }
  • }
  • methods: {
  • minus() {
  • this.result--;
  • this.$emit('input', {res: this.result, other: '--'})
  • },
  • plus() {
  • this.result++;
  • this.$emit('input', {res: this.result, other: '++'})
  • }
  • }
  • }
  • </script>
  • <style lang="stylus" scoped>
  • button
  • border 0
  • outline 0
  • border-radius 3px
  • button:nth-child(2)
  • width 200px
  • </style>

  • 免責聲明!

    本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



     
    粵ICP備18138465號   © 2018-2025 CODEPRJ.COM