午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Vue實現手機計算器

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

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

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

Vue實現手機計算器

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

Vue實現手機計算器

頁面視圖

Vue實現手機計算器

JS

Vue實現手機計算器

Vue實現手機計算器

Vue實現手機計算器

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

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

標簽: Vue
相關文章:
主站蜘蛛池模板: www国产亚洲精品久久麻豆 | 天天综合网久久综合网 | 欧美成人区 | 在线观看毛片网站 | av在线影院| 色综合久久88色综合天天 | 免费a在线| 岛国av免费在线观看 | 中文字幕久久久久 | 欧美91| 4438亚洲最大 | 日批在线看 | 最新中文字幕 | 人人插人人插 | 亚洲天堂精品在线 | 狠狠2019| 婷婷91| 小黄书在线观看 | 久久99精品久久久久久园产越南 | 伊人再见免费在线观看高清版 | 国产91免费在线观看 | 91亚洲国产成人精品性色 | 欧美日韩啪啪 | 欧美黄色aaa | 九九操| 亚洲制服无码 | 中文字幕一区二区三区四区不卡 | 成人午夜免费在线观看 | 国产黄色片在线观看 | 国产一区二区观看 | 成年人网站免费看 | 亚洲青草视频 | 欧美一区二区在线观看视频 | 亚洲一区二区三区在线观看视频 | 黄色免费视频网站 | 欧美黄页 | 亚洲国产91 | 欧美1区2区 | 毛片毛片女人毛片毛片 | 中文字幕视频网站 | 91免费高清 |