Skip to content

x-data Documentation Not Clear #1151

Answered by KevinBatdorf
jherdman asked this question in 1. Help
Discussion options

You must be logged in to vote

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:
<div x-data="{ count: 0 }">

explain this without referring to Vue

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.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jherdman
Comment options

@KevinBatdorf
Comment options

@jherdman
Comment options

@KevinBatdorf
Comment options

@jherdman
Comment options

Answer selected by jherdman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants