Vue.js 如何限制按钮中的增量?

Vue.js 如何限制按钮中的增量?,vue.js,nuxt.js,Vue.js,Nuxt.js,我希望“步长”值不超过3,有什么可以帮助我 这是我的密码 {{step}} 这肯定会有帮助: {{step}} 增量{ 如果this.step

我希望“步长”值不超过3,有什么可以帮助我

这是我的密码

{{step}}
这肯定会有帮助:

{{step}} 增量{ 如果this.step<3 this.step++; }
这肯定会有帮助:

{{step}} 增量{ 如果this.step<3 this.step++; }
我建议另一种方法,我认为这是一种更干净的方法:

<template>
  <div>
    <label>{{ step }}</label>
    <button @click="increment" :disabled="shouldStopIncrement">{{ stepLabel }</button>
  </div>
</template>

<script>
export default {
  name: 'SampleComponent',
  data() { 
    return { 
      step: 0 
    } 
  },
  computed: {
    stepLabel({ step }) {
      return step === 3 ? 'Kirim' : 'Selanjutnya';
    },
    shouldStopIncrement({ step }) {
      return step >= 3;
    }
  },
  methods: {
    increment() {
      this.step++;
    }
  }
}
</script>

我建议另一种方法,我认为这是一种更干净的方法:

<template>
  <div>
    <label>{{ step }}</label>
    <button @click="increment" :disabled="shouldStopIncrement">{{ stepLabel }</button>
  </div>
</template>

<script>
export default {
  name: 'SampleComponent',
  data() { 
    return { 
      step: 0 
    } 
  },
  computed: {
    stepLabel({ step }) {
      return step === 3 ? 'Kirim' : 'Selanjutnya';
    },
    shouldStopIncrement({ step }) {
      return step >= 3;
    }
  },
  methods: {
    increment() {
      this.step++;
    }
  }
}
</script>