色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Vue實現(xiàn)手機計算器

瀏覽:104日期:2022-12-05 13:58:39

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

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

Vue實現(xiàn)手機計算器

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

Vue實現(xiàn)手機計算器

頁面視圖

Vue實現(xiàn)手機計算器

JS

Vue實現(xiàn)手機計算器

Vue實現(xiàn)手機計算器

Vue實現(xiàn)手機計算器

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

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 99r精品在线 | 亚洲精品一区二区三区在线观看 | 久久99久久99| 欧美日韩 国产区 在线观看 | 久久国产午夜精品理论片34页 | 亚洲成a人片在线v观看 | 亚洲精品成人网久久久久久 | 黄网站免费在线 | 久久福利青草免费精品 | 韩国精品欧美一区二区三区 | 91精品国产综合久久久久久 | 国产免费久久精品久久久 | 亚洲一区二区三区国产精品 | 国产一区亚洲欧美成人 | 美女黄色免费看 | 中文字幕亚洲一区二区va在线 | 亚洲字幕波多野结衣作品 | 男女性男女刺激大片免费观看 | 99久久国产综合精品成人影院 | a毛片全部免费播放 | 天空在线观看免费完整 | 久99久精品视频免费观看v | 免费一级欧美性大片 | 国产91专区 | 久久久青青久久国产精品 | 亚洲日韩视频免费观看 | 精品久久久久久久久久中文字幕 | 久久网站免费观看 | 欧美啪啪一级毛片 | 91欧美在线视频 | 精品欧美一区二区三区在线 | 亚洲欧美自拍视频 | 国产成人精品三区 | 国产一在线精品一区在线观看 | 91精品国产色综合久久不 | 超级碰碰碰视频视频在线视频 | 久久综合久久美利坚合众国 | 日韩在线一区二区三区 | 成人男女18免费o | 亚洲精品视频在线 | 国产91无套剧情在线播放 |