x-bind to $root #3784
Answered
by
ekwoka
manuelmeister
asked this question in
1. Help
x-bind to $root
#3784
-
It would be really nice to have a way to x-bind to the reusable component without declaring x-bind besides x-data: Alpine.data("link", () => ({
clickable: false,
click(event) {
if (!this.clickable) {
event.preventDefault();
}
},
root: {
["x-on:click.capture"]: function (event) {
this.click(event);
},
["x-on:keydown.enter"]: function (event) {
this.click(event);
},
["x-on:keydown.shift"]: function () {
this.clickable = true;
},
["x-on:keyup"]: function () {
this.clickable = false;
},
}
})); How we have to do it now: <a x-data="link" x-bind="root">Read more</a> How I would love to do it: <a x-data="link">Read more</a> |
Beta Was this translation helpful? Give feedback.
Answered by
ekwoka
Sep 26, 2023
Replies: 2 comments 11 replies
-
There already is: |
Beta Was this translation helpful? Give feedback.
0 replies
-
oh, you mean, have like a property on the x-data that auto binds stuff. So you can add to your data init() {
Alpine.bind(this.$root, this.root)
} And it would do that. Also, as a style thing, the normal way to define a method on an object is ["x-on:click.capture"](event) {
this.click(event);
} not with a function expression |
Beta Was this translation helpful? Give feedback.
11 replies
Answer selected by
manuelmeister
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
oh, you mean, have like a property on the x-data that auto binds stuff.
So you can add to your data
And it would do that.
Also, as a style thing, the normal way to define a method on an object is
not with a function expression