Created
December 8, 2023 17:49
-
-
Save inxilpro/ac2cd8898df348335db6887ce6df5f88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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