vue-model實現簡易計算器
本文實例為大家分享了vue-model實現簡易計算器的具體代碼,供大家參考,具體內容如下
<!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://m.4tl426be.cn/lib/vue-2.4.0.js'></script></head><body> <div > <!-- 數字一 --> <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> <!-- 數字2 --> <input type='text' v-model=’n2’ placeholder='0'> <!-- 等號 --> <input type='button' value=’=’ > <!-- 結果 --> <input type='text' v-model=’result’ placeholder='0'> <!-- 確定按鈕 --> <input type='button' value=’結果’ @click=’calc’> <!-- 歸零 --> <input type='button' value=’歸零’ @click=’zero’> </div> <script> var vm = new Vue({ el: ’#app’, //表示當前new的這個實例要控制頁面上的那個區域 data: { //data屬性存放著 el 中要用到的數據 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; // } // 簡寫 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>
關于計算器相關技術文章請點擊專題: javascript計算器功能匯總
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章:
1. React+umi+typeScript創建項目的過程2. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執行過程解析3. SharePoint Server 2019新特性介紹4. ASP中常用的22個FSO文件操作函數整理5. 三個不常見的 HTML5 實用新特性簡介6. ASP調用WebService轉化成JSON數據,附json.min.asp7. .Net core 的熱插拔機制的深入探索及卸載問題求救指南8. 無線標記語言(WML)基礎之WMLScript 基礎第1/2頁9. 讀大數據量的XML文件的讀取問題10. 解決ASP中http狀態跳轉返回錯誤頁的問題
