<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() {
            	// ~~this.a可去除this.a数字前的0
                this.a = parseInt(~~this.a);
                this.b = parseInt(~~this.b);

                this.sign = this.a > this.b ? ">" : (this.a == this.b ? "=" : "<");
            }
        }
    })
</script>
Logo

前往低代码交流专区

更多推荐