x-data Documentation Not Clear #1151
-
In the README documentation for
I don't find this particularly helpful as I'm not familiar with Vue. Would someone be able to explain this without referring to Vue for me? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
In Vue you have something like this: const data = function () {
return {
count: 0
}
}
Vue.component('button-counter', { data: data }, template) In Alpine: <div x-data="data()"></div>
<script>
const data = function() {
return {
count: 0
}
}
</script> Or for short:
In summary, you're passing in the initial "state" of the component, ie. defining all of it's properties and values. You can also pass in methods too. Let me know if you need more clarification. |
Beta Was this translation helpful? Give feedback.
In Vue you have something like this:
In Alpine:
Or for short:
<div x-data="{ count: 0 }">
In summary, you're passing in the initial "state" of the component, ie. defining all of it's properties and values. You can also pass in methods too. Let me know if you need more clarification.