Created
August 4, 2020 01:10
-
-
Save PKTseng/01086e775d63b53dcd9329e577a5eeef to your computer and use it in GitHub Desktop.
computed & watch 比較
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<input v-model="a">+ | |
<input v-model="b">= | |
<input v-model="c"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment