vue-model實(shí)現(xiàn)簡(jiǎn)易計(jì)算器
本文實(shí)例為大家分享了vue-model實(shí)現(xiàn)簡(jiǎn)易計(jì)算器的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title>Vue</title> <script src='http://www.cgvv.com.cn/lib/vue-2.4.0.js'></script></head><body> <div > <!-- 數(shù)字一 --> <input type='text' v-model=’n1’ placeholder='0'> <!-- 加減乘除 --> <select v-model=’opt’> <option value='+'> + </option> <option value='-'>-</option> <option value='*'>*</option> <option value='/'>/</option> </select> <!-- 數(shù)字2 --> <input type='text' v-model=’n2’ placeholder='0'> <!-- 等號(hào) --> <input type='button' value=’=’ > <!-- 結(jié)果 --> <input type='text' v-model=’result’ placeholder='0'> <!-- 確定按鈕 --> <input type='button' value=’結(jié)果’ @click=’calc’> <!-- 歸零 --> <input type='button' value=’歸零’ @click=’zero’> </div> <script> var vm = new Vue({ el: ’#app’, //表示當(dāng)前new的這個(gè)實(shí)例要控制頁(yè)面上的那個(gè)區(qū)域 data: { //data屬性存放著 el 中要用到的數(shù)據(jù) n1: ’’, n2:’’, result:’’, opt: ’+’ }, methods:{ calc(){ // switch(this.opt){ // case ’+’: // this.result = parseInt(this.n1) + parseInt(this.n2) // break; // case ’-’: // this.result = parseInt(this.n1) - parseInt(this.n2) // break; // case ’*’: // this.result = parseInt(this.n1) * parseInt(this.n2) // break; // case ’/’: // this.result = parseInt(this.n1) / parseInt(this.n2) // break; // } // 簡(jiǎn)寫(xiě) var codeStr = ’parseInt(this.n1) ’+ this.opt +’ parseInt(this.n2)’ this.result = eval(codeStr) }, zero(){ this.n1 = ’’, this.n2 = ’’, this.result = ’’, this.opt = ’+’ } } }) </script></body></html>
關(guān)于計(jì)算器相關(guān)技術(shù)文章請(qǐng)點(diǎn)擊專題: javascript計(jì)算器功能匯總
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼2. PHP橋接模式Bridge Pattern的優(yōu)點(diǎn)與實(shí)現(xiàn)過(guò)程3. asp.net core項(xiàng)目授權(quán)流程詳解4. html中的form不提交(排除)某些input 原創(chuàng)5. CSS3中Transition屬性詳解以及示例分享6. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼7. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式8. 開(kāi)發(fā)效率翻倍的Web API使用技巧9. jsp文件下載功能實(shí)現(xiàn)代碼10. ASP常用日期格式化函數(shù) FormatDate()
