您好,登錄后才能下訂單哦!
這篇文章主要介紹“Vue怎么實(shí)現(xiàn)簡單網(wǎng)頁計(jì)算器”,在日常操作中,相信很多人在Vue怎么實(shí)現(xiàn)簡單網(wǎng)頁計(jì)算器問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Vue怎么實(shí)現(xiàn)簡單網(wǎng)頁計(jì)算器”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
1、 考核知識(shí)點(diǎn)
2、 創(chuàng)建vue實(shí)例和對v-model內(nèi)置指令的使用
3、 練習(xí)目標(biāo)
創(chuàng)建vue實(shí)例。
掌握v-model內(nèi)置指令的使用。
4、 需求分析
用戶通過選擇計(jì)算方法和數(shù)據(jù)輸入,得到計(jì)算結(jié)果。
5、 案例分析
效果如圖所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>計(jì)算器</title> <script src="vue.js"></script> <style> .result{ font-size: 30px; } </style> </head> <body> <div id="app"> <!-- 定義頁面結(jié)構(gòu) --> <div class="calc"> <input type="radio" value="1" v-model="fuhao"/>加法 <input type="radio" value="2" v-model="fuhao"/>減法 <input type="radio" value="3" v-model="fuhao"/>乘法 <input type="radio" value="4" v-model="fuhao"/>除法 <ul> <li> 數(shù)據(jù)1:<input type="text" v-model="num1"> </li> <li> 數(shù)據(jù)2:<input type="text" v-model="num2"> </li> <li> <input type="button" value="計(jì)算" @click='calc()'> </li> </ul> <div class="result">結(jié)果:{{result}}</div> </div> </div> <script> var vm = new Vue({ el: '#app', // 定義初始數(shù)據(jù) data: { fuhao: '1', num1: '', num2: '', result: '' }, // 定義事件處理函數(shù)Calc methods: { calc() { if (!this.num1 || !this.num2) { this.result = '輸入的數(shù)不能為空' } else { if (this.fuhao == 1) { this.result = parseInt(this.num1) + parseInt(this.num2) } if (this.fuhao == 2) { this.result = parseInt(this.num1) - parseInt(this.num2) } if (this.fuhao == 3) { this.result = parseInt(this.num1) * parseInt(this.num2) } if (this.fuhao == 4) { this.result = parseInt(this.num1) / parseInt(this.num2) } } } } }) </script> </body> </html>
到此,關(guān)于“Vue怎么實(shí)現(xiàn)簡單網(wǎng)頁計(jì)算器”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。