Reputation: 459
I have checked similar question, but there is still one thing that is unclear to me:
Can I pass a parameter in emit on event hub, but I need parameter to be VALUE and not the VARIABLE which stores value. So for example: eventHub.$emit('test_emit', true)
and the method which is called on test_emit
should have it's parameter set on true.
Upvotes: 1
Views: 1365
Reputation: 2254
From the similar question that you provided, you would just replace name
with true
when you are emitting event
methods: {
showModal(name) { this.bus.$emit('showModal', true); },
}
created() {
// `show` will have the value that you emitted
this.bus.$on('showModal', (show) => console.log(show);
}
Upvotes: 2
Reputation: 223
Sure you can, what you cannot do is to pass more then one variable (like eventHub.$emit('test_emit', true, false)
as $emit accepts only one additional parameter (that can be the value or an object containing the key: value associations, also know as payload.
Upvotes: 1