VueJs Beginners part 2 – Methods

To add methods to a component instance we use the methods option.
we can define them the way we defined data and indeed methods is a object of functions.

const app = Vue.createApp({
data() {
return {
count: 0
}
},
methods: {


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Hash

To add methods to a component instance we use the methods option.
we can define them the way we defined data and indeed methods is a object of functions.

const app = Vue.createApp({
  data() {
    return {
      count: 0
    }
  },
  methods: {
    increment() {
      this.count++
    }
  },
)}

Event and key Modifiers:

It is a very common need to call something like event.preventDefault() inside event handlers. it can be done in method itself but there are some modifiers to apply them easier.

examples:

@click.right
@click.prevent.stop
@keyup.13

<!-- the submit event will no longer reload the page -->
<form @submit.prevent="onSubmit"></form>

<!-- only call `submit` when the `key` is `Enter` -->
<input @keyup.enter="submit" />

do you want more check here

Run and edit them yourself here


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Hash


Print Share Comment Cite Upload Translate Updates
APA

Hash | Sciencx (2022-10-29T21:14:12+00:00) VueJs Beginners part 2 – Methods. Retrieved from https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/

MLA
" » VueJs Beginners part 2 – Methods." Hash | Sciencx - Saturday October 29, 2022, https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/
HARVARD
Hash | Sciencx Saturday October 29, 2022 » VueJs Beginners part 2 – Methods., viewed ,<https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/>
VANCOUVER
Hash | Sciencx - » VueJs Beginners part 2 – Methods. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/
CHICAGO
" » VueJs Beginners part 2 – Methods." Hash | Sciencx - Accessed . https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/
IEEE
" » VueJs Beginners part 2 – Methods." Hash | Sciencx [Online]. Available: https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/. [Accessed: ]
rf:citation
» VueJs Beginners part 2 – Methods | Hash | Sciencx | https://www.scien.cx/2022/10/29/vuejs-beginners-part-2-methods/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.