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.leifengta.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)寫 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. 詳解Android studio 動(dòng)態(tài)fragment的用法2. 編程語(yǔ)言PHP在Web開(kāi)發(fā)領(lǐng)域的優(yōu)勢(shì)在哪?3. 什么是python的自省4. Spring Boot和Thymeleaf整合結(jié)合JPA實(shí)現(xiàn)分頁(yè)效果(實(shí)例代碼)5. 解決Android studio xml界面無(wú)法預(yù)覽問(wèn)題6. 基于android studio的layout的xml文件的創(chuàng)建方式7. Android如何加載Base64編碼格式圖片8. Springboot Druid 自定義加密數(shù)據(jù)庫(kù)密碼的幾種方案9. Vue封裝一個(gè)TodoList的案例與瀏覽器本地緩存的應(yīng)用實(shí)現(xiàn)10. 圖文詳解vue中proto文件的函數(shù)調(diào)用

網(wǎng)公網(wǎng)安備