gpt4 book ai didi

vue.js - 如何限制按钮的增量?

转载 作者:行者123 更新时间:2023-12-02 19:06:47 26 4
gpt4 key购买 nike

我希望“step”值不超过3,有什么可以帮助我吗?

这是我的代码

     <label>{{step}}</label>
<button class="btn btn-red btn-next" @click="step < 3;step++; " v-html="step === 3 ? 'Kirim' :
'Selanjutnya'">
</button>

最佳答案

我建议另一种方法,在我看来这是一种“更干净”的方法:

<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>

关于vue.js - 如何限制按钮的增量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64920842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com