Answer the question
In order to leave comments, you need to log in
How to pass parameter to props function in VUE?
There is such a code
<button-ui :classes="['details-button', 'secondary']" title="Описание"
:click-handler="openModal"></button-ui>
const app = new Vue({
el: '#app',
store,
methods: {
openModal(value) {
console.log(value);
}
},
});
<button-ui :classes="['details-button', 'secondary']" title="Описание"
:click-handler="openModal('test')"></button-ui>
Answer the question
In order to leave comments, you need to log in
I came up with a solution myself - you can pass an array of arguments to neighboring props and inside the component, use the spread operator to expand them into function arguments.
Try like this:
<button-ui :classes="['details-button', 'secondary']" title="Описание"
@click="openModal('test')"></button-ui>
I don’t know, I even output everything to the console in this vein
<body>
<div id="app">
{{ message}}
<button-ui :classes="['details-button', 'secondary']" title="Описание" :click-handler="openModal('test')">
</button-ui>
</div>
<script>
Vue.component('button-ui', {
data: function () {
return {
count: 0
}
},
template: '<button>жми</button>'
})
new Vue({
el: "#app",
data: {
message: 'You loaded this page on ' + new Date().toLocaleString()
},
methods: {
openModal(value) {
console.log(value);
}
}
})
</script>
</body>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question