vue-model實(shí)現(xiàn)簡(jiǎn)易計(jì)算器
更新時(shí)間:2020年08月17日 14:28:58 作者:ヽ錯(cuò)落不堪的年華。
這篇文章主要為大家詳細(xì)介紹了vue-model實(shí)現(xiàn)簡(jiǎn)易計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(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="../lib/vue-2.4.0.js"></script> </head> <body> <div id="app" > <!-- 數(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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue跨域處理方式(vue項(xiàng)目中baseUrl設(shè)置問題)
這篇文章主要介紹了vue跨域處理方式(vue項(xiàng)目中baseUrl設(shè)置問題),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05vue路由警告:Duplicate named routes definition問題
這篇文章主要介紹了vue路由警告:Duplicate named routes definition問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09快速修改antd?vue單個(gè)組件的默認(rèn)樣式
這篇文章主要介紹了快速修改antd?vue單個(gè)組件的默認(rèn)樣式方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2022-08-08