Created
June 10, 2022 11:55
-
-
Save Accudio/4a5f4340bb60f2fbf2c65a810f6da463 to your computer and use it in GitHub Desktop.
Synchronising a property on `window` and an Alpine.js property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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