Skip to content

Instantly share code, notes, and snippets.

@PKTseng
Created August 4, 2020 01:11
Show Gist options
  • Save PKTseng/b4adea175974fcd3b1d5dadb46773c8d to your computer and use it in GitHub Desktop.
Save PKTseng/b4adea175974fcd3b1d5dadb46773c8d to your computer and use it in GitHub Desktop.
computed & watch 比較
<div id="app">
 <input v-model="a">+
 <input v-model="b">=
 <input v-model="c">
</div>
new Vue({
 el:"#app",
 data:{
a: 0,
b: 0,
c: 0
 },
 watch:{
a(val){
this.c = parseInt(val, 10) +parseInt(this.b, 10) ;
 },
 b(val){
this.c = parseInt(val, 10) + parseInt(this.a, 10);
},
 }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment