Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created December 8, 2023 17:49
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 inxilpro/ac2cd8898df348335db6887ce6df5f88 to your computer and use it in GitHub Desktop.
Save inxilpro/ac2cd8898df348335db6887ce6df5f88 to your computer and use it in GitHub Desktop.
<x-chart wire:model="chartData" />
<!-- I can be explicit if I want… -->
<div x-modelable="values" x-data="{
values: [],
init() {
const chart = new Chart(this.$refs.canvas, {
data: this.values
});
Alpine.watch('values', fn() => chart.update(this.values));
}
}">
</div>
<!-- Or, if I don't set up a modelable -->
<div x-data="{
init() {
const chart = new Chart(this.$refs.canvas, {
data: this.model // This always exists if I don't define it
});
Alpine.watch('model', fn() => chart.update(this.model));
}
}">
</div>
<!-- Which is just essentially… -->
<div x-modelable="model" x-data="{
model: [],
// ...
}">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment