Skip to content

Instantly share code, notes, and snippets.

@Accudio
Created June 10, 2022 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Accudio/4a5f4340bb60f2fbf2c65a810f6da463 to your computer and use it in GitHub Desktop.
Save Accudio/4a5f4340bb60f2fbf2c65a810f6da463 to your computer and use it in GitHub Desktop.
Synchronising a property on `window` and an Alpine.js property
<div x-data="{
count: 4,
init() {
const self = this
Object.defineProperty(window, 'count', {
enumerable: true,
configurable: true,
get: function() {
return self.count
},
set: function(val) {
self.count = val
}
});
}
}" x-text="count"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment