How to binding x-cloak
#4832
-
Alpine.js versionv3.15.12 Browser and operating systemChrome on Windows What do you need help with?Based on the documentation, I can bind Alpine directives directly, however I can't find a way to bind // Not working example
<span x-data="withCounter('{{ $count }}', '{{ $eventName }}')" x-bind="counter"></span>
// Working example
<span x-data="withCounter('{{ $count }}', '{{ $eventName }}')" x-cloak x-bind="counter"></span>Alpine.data('withCounter', (value, eventName) => ({
count: value,
get show() {
return Boolean(this.count && this.count !== '0')
},
counter: {
// This doesnt work
['x-cloak']() {
return true
},
['x-on:' + eventName + '.window'](e) {
this.count = e.detail.count
},
['x-show']() {
return this.show
},
['x-text']() {
return this.count
},
},
}))How do you expect it to work?I hope there is a documentation about it. All I can find was directives with a value Please confirm
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
It wouldn't make sense to bind |
Beta Was this translation helpful? Give feedback.
x-cloakcannot be "bound". It needs to exist on the HTML before AlpineJS is initialized. All Alpine does is remove the attribute after it has initialized.