Last active
August 31, 2023 07:00
-
-
Save yulvil/694655e1c9fff66533df5cdecc5ebe31 to your computer and use it in GitHub Desktop.
vue.js example with button on-click event
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
| <html> | |
| <head> | |
| <script src="https://unpkg.com/vue/dist/vue.js"></script> | |
| </head> | |
| <body> | |
| <div id="example"> | |
| <form action="javascript:void(0);"> | |
| <button v-on:click="dosomething">Add 1</button> | |
| {{ counter }} {{ message }} | |
| </form> | |
| </div> | |
| <script> | |
| var places = ['World', 'America', 'Europe', 'Asia'] | |
| var object = { | |
| message: 'Hello world!', | |
| counter: 0 | |
| } | |
| new Vue({ | |
| el: '#example', | |
| data: object, | |
| methods: { | |
| dosomething: function (event) { | |
| // `this` inside methods points to the Vue instance | |
| // `event` is the native DOM event | |
| // alert(event.target.tagName); | |
| this.counter += 1; | |
| this.message = 'Hello ' + (places[this.counter%4]) + '!'; | |
| } | |
| } | |
| }) | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment