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

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

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

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

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

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

頁面視圖

JS

new Vue({
   el: "#app",
   data: {
    equation: '0',
    isDecimalAdded: false, //防止在一組數(shù)字中間輸入超過一個小數(shù)位
    isOperatorAdded: false, //判斷之否已點(diǎn)擊 加、減、乘、除,防止連續(xù)點(diǎn)擊超過一個運(yùn)算符號
    isStarted: false, //判斷計(jì)算器是否已經(jīng)開始輸入數(shù)字,用于正負(fù)數(shù)和百分比計(jì)算的時候作一些判斷
   },
   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() { //等于號的時候
     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ù)號
     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ù)字中間輸入超過一個小數(shù)位
     this.isOperatorAdded = false //判斷之否已點(diǎn)擊 加、減、乘、除,防止連續(xù)點(diǎn)擊超過一個運(yùn)算符號
     this.isStarted = false //判斷計(jì)算器是否已經(jīng)開始輸入數(shù)字,用于正負(fù)數(shù)和百分比計(jì)算的時候作一些判斷
    }
   }
})

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

相關(guān)文章

最新評論

石阡县| 奉新县| 沿河| 灵丘县| 星座| 普陀区| 吴旗县| 宜良县| 双城市| 南阳市| 琼海市| 嘉义县| 乌拉特中旗| 手游| 礼泉县| 翼城县| 卓资县| 清流县| 宁津县| 买车| 嘉峪关市| 库伦旗| 大名县| 隆子县| 临潭县| 平塘县| 嘉荫县| 黄平县| 富阳市| 琼中| 东宁县| 嘉黎县| 大洼县| 宝兴县| 友谊县| 安多县| 东城区| 夏津县| 常德市| 瑞安市| 利川市|