Last active
May 8, 2020 12:22
-
-
Save barnslig/1d937af4455fdedc773e0fc45ece152d to your computer and use it in GitHub Desktop.
Vue.js: watch vs computed
This file contains hidden or 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
| <script> | |
| export default { | |
| props: { | |
| foobar: { | |
| type: String, | |
| required: true | |
| } | |
| }, | |
| data() { | |
| return { | |
| myFoobar: null | |
| }; | |
| }, | |
| watch: { | |
| foobar() { | |
| this.updateMyFoobar(); | |
| } | |
| }, | |
| mounted() { | |
| this.updateMyFoobar(); | |
| }, | |
| methods: { | |
| updateMyFoobar() { | |
| this.myFoobar = `${this.foobar}-baz`; | |
| } | |
| } | |
| }; | |
| </script> |
This file contains hidden or 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
| <script> | |
| export default { | |
| props: { | |
| foobar: { | |
| type: String, | |
| required: true | |
| } | |
| }, | |
| computed: { | |
| myFoobar() { | |
| return `${this.foobar}-baz`; | |
| } | |
| } | |
| }; | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment