最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue實(shí)現(xiàn)手機(jī)計(jì)算器

 更新時(shí)間:2020年08月17日 14:01:13   作者:昵稱~  
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)手機(jī)計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Vue制作仿手機(jī)計(jì)算器的具體代碼,供大家參考,具體內(nèi)容如下

1.首先是把樣式做出來,按鈕是0-9,還有加減乘除,百分號(hào),清除按鈕,小數(shù)點(diǎn),等號(hào)、等等

2.把官方網(wǎng)站的JS插件引用,cn.vuejs.org/v2/guide/

頁面視圖

JS

new Vue({
   el: "#app",
   data: {
    equation: '0',
    isDecimalAdded: false, //防止在一組數(shù)字中間輸入超過一個(gè)小數(shù)位
    isOperatorAdded: false, //判斷之否已點(diǎn)擊 加、減、乘、除,防止連續(xù)點(diǎn)擊超過一個(gè)運(yùn)算符號(hào)
    isStarted: false, //判斷計(jì)算器是否已經(jīng)開始輸入數(shù)字,用于正負(fù)數(shù)和百分比計(jì)算的時(shí)候作一些判斷
   },
   methods: {
    //Check if the character is + - × ÷
    isOperator(character) { //用來判斷character 是否加減乘除
     return ['+', '-', '×', '÷'].indexOf(character) > -1
    },
    append(character) { //append(character)加減乘除
     if (this.equation === '0' && !this.isOperator(character)) {
      if (character === '.') {
       this.equation += '' + character
       this.isDecimalAdded = true
      } else {
       this.equation = '' + character
      }
      this.isStarted = true
      return
     }

     if (!this.isOperator(character)) {
      if (character === '.' && this.isDecimalAdded) {
       return
      }

      if (character === '.') {
       this.isDecimalAdded = true
       this.isOperatorAdded = true
      } else {
       this.isOperatorAdded = false
      }
      this.equation += '' + character
     }

     if (this.isOperator(character) && !this.isOperatorAdded) {
      this.equation += '' + character
      this.isDecimalAdded = false
      this.isOperatorAdded = true
     }
    },
    calculate() { //等于號(hào)的時(shí)候
     let result = this.equation.replace(new RegExp('×', 'g'), '*').replace(new RegExp('÷', 'g'), '/')
     this.equation = parseFloat(eval(result).toFixed(9)).toString()
     this.isDecimalAdded = false
     this.isOperatorAdded = false
    },
    calculateToggle() { //點(diǎn)擊正負(fù)號(hào)
     if (this.isOperatorAdded || !this.isStarted) {
      true
     }

     this.equation = this.equation + '* -1'
     this.calculate()
    },
    calculatePercentage() { //點(diǎn)擊百分比
     if (this.isOperatorAdded || !this.isStarted) {
      true
     }

     this.equation = this.equation + '* 0.01'
     this.calculate()
    },
    clear() { //點(diǎn)擊AC
     this.equation = '0'
     this.isDecimalAdded = false //防止在一組數(shù)字中間輸入超過一個(gè)小數(shù)位
     this.isOperatorAdded = false //判斷之否已點(diǎn)擊 加、減、乘、除,防止連續(xù)點(diǎn)擊超過一個(gè)運(yùn)算符號(hào)
     this.isStarted = false //判斷計(jì)算器是否已經(jīng)開始輸入數(shù)字,用于正負(fù)數(shù)和百分比計(jì)算的時(shí)候作一些判斷
    }
   }
})

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

北川| 丹凤县| 自贡市| 葫芦岛市| 卓尼县| 綦江县| 中超| 神木县| 贵港市| 长沙县| 黄冈市| 彭阳县| 乌兰浩特市| 马龙县| 彭泽县| 深水埗区| 沁源县| 榆林市| 莆田市| 酒泉市| 高安市| 宜君县| 灌云县| 大厂| 平舆县| 敖汉旗| 团风县| 洱源县| 宁河县| 通州市| 分宜县| 增城市| 固安县| 辛集市| 涡阳县| 海南省| 阜新| 婺源县| 利川市| 阳新县| 天祝|