vue实现比大小

时间:2025-02-14 11:39:14
<body> <div id="app"> <input type="text" v-model="a" placeholder="请输入第一个数字"> <input type="text" v-model="sign"> <input type="text" v-model="b" placeholder="请输入第二个数字"> <button @click="compare">点击比较</button> </div> </body> <script> var nv = new Vue({ el: "#app", data: { a: '', b: '', sign: '?' }, methods: { compare() { // ~~可去除数字前的0 this.a = parseInt(~~this.a); this.b = parseInt(~~this.b); this.sign = this.a > this.b ? ">" : (this.a == this.b ? "=" : "<"); } } }) </script>