亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue實(shí)現(xiàn)簡單計(jì)算器案例

 更新時間:2020年02月25日 09:23:44   作者:LitongZero  
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)簡單計(jì)算器案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

利用Vue.js寫的一個簡單的計(jì)算器。非常簡單的案例。

通過這個案例,練習(xí)一下Vue的語法。

通過案例可以看出,Vue.js解放了DOM操作。

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Vue計(jì)算器</title>
</head>
<body>
<div id="app">
 <input type="number" v-model="num1">
 <select v-model="operation">
  <option value="0">+</option>
  <option value="1">-</option>
  <option value="2">*</option>
  <option value="3">/</option>
 </select>
 <input type="number" v-model="num2">
 <button @click="calculate">=</button>
 <strong>{{results}}</strong>
</div>
<script src="node_modules/vue/dist/vue.js"></script>
<script>
 new Vue({
  el: '#app',
  data:{
   operation: '0',
   results: '0',
   num1:0,
   num2:0,
  },
  methods:{
   calculate:function(){
    switch (this.operation) {
     case '0' :
      this.results = parseInt(this.num1) + parseInt(this.num2);
      break;
     case '1' :
      this.results = this.num1-this.num2;
      break;
     case '2' :
      this.results = this.num1*this.num2;
      break;
     case '3' :
      this.results = this.num1/this.num2;
      break;
    }
   }
  }
 })
 
</script>
 
</body>
</html>

截圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論