-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
invoking event handler with args evokes access to the event object #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You could do something like this: <div id="main">
<div v-on="click: dismiss">
<h3>Click Something</h3>
<ul>
<li v-repeat="choices" v-text="$value" v-on="click: selectChoice">
</li>
</ul>
</div>
<h3>Message</h3>
<p v-text="mainMessage"></p>
<p v-text="selectMessage"></p>
</div> new Vue({
el: '#main',
data: {
choices: ['hi', 'bye', 'g\'day']
},
methods: {
dismiss: function() {
this.selectMessage = '';
this.mainMessage = 'Dismissed';
},
selectChoice: function(e) {
e.stopPropagation();
this.selectMessage = e.srcElement.innerText;
this.mainMessage = '';
}
}
}); That will get it working for you now, if you're using the dev branch with commit 835dd0e (See #161). But, there should probably be a way to invoke handlers with expressions using |
That's what I use atm, but it's an ugly hack. It'd be more elegant to be be able to write something like selectChoice(this, e). |
you can get access to selectChoice: function (e) {
e.stopPropagation();
// do something with `e.targetVM.$value`
} Basically, if you have logic that needs more than one expression, put it in a method. |
Every time I miss something like this, I think "I don't remember that being in the docs". So, I go look and.... of course it's there, right in the first paragraph :) |
With a setup like this:
since selectChoice is invoked with argument this.$value, it loses access to the event object. as a result, if it needs to stop event from propagating, it can't.
Is there currently a solution to this problem?
The text was updated successfully, but these errors were encountered: