Vue练习二十二:03_04_输入2个数字比较大小

Demo 在线地址:
https://sx00xs.github.io/test/22/index.html
---------------------------------------------------------------
ide: vscode
文件格式:.vue
解析:(待补)

<template>
  <div id="app">
    <input type="text" class="f-text" v-model="num1" @keyup="handleNum1">
    <strong>vs</strong>
    <input type="text" class="f-text" v-model="num2" @keyup="handleNum2">
    <input @click="handleBignum" type="button" value="最大的数是 &raquo;" class="f-btn"><span>{{which}}</span>
  </div>
</template>
<script>
export default {
  data:function(){
    return{
      num1:'',
      num2:'',
      which:'?'
    }
  },
  methods:{
    handleNum1(){
      this.num1=this.num1.replace(/[^\d]/,'');
    },
    handleNum2(){
      this.num2=this.num2.replace(/[^\d]/,'');
    },
    handleBignum(){
      (this.num1=='' || this.num2=='') ?
      alert('请输入数字!') :
      this.which=Math.max(this.num1,this.num2);
    }
  }
}
</script>

 

posted @ 2019-07-29 19:53  sx00xs  阅读(3616)  评论(0编辑  收藏  举报