vuejs event code example
Example 1: root template
'DIRS': [BASE_DIR / 'templates'],
Example 2: how to access both child event param and parent param in vue
<template>
<ul>
<product v-for="product in products"
:product="product"
@add="addToChart" />
</ul>
</template>
<script>
const Product = {
props: ["product"],
render(h) {
return h("li", { on: { click: this.click } }, this.product);
},
methods: {
click() {
this.$emit("add", { product: this.product, quantity: 42 });
}
}
};
export default {
data() {
return {
products: ["Foo", "Bar"]
};
},
components: {
Product
},
methods: {
addToChart({ product, quantity }) {
console.log(product, quantity);
}
}
}
</script>
Example 3: vue js button click
<div id="example-2">
<button v-on:click="greet">Greet</button>
</div>
Example 4: event vueks
<div id="example-3">
<button v-on:click="say('salut')">Dire salut</button>
<button v-on:click="say('quoi')">Dire quoi</button>
</div>
Example 5: event vueks
new Vue({
el: '#example-3',
methods: {
say: function (message) {
alert(message)
}
}
})
Example 6: vuejs v-on
<div v-on:javascriptEvent = "method"></div>