使用
$el.dataset.value
可以访问当前元素的 data-value 值,可以在 @click 事件中使用它,也可以直接在 filterPosts() 方法中使用:
@click="total += parseInt($el.dataset.value); filterPosts(<?= $category->term_id; ?>)">
或:
Alpine.data("filterPosts", (adminURL) => ({
......
total: 0, // want to get the value from the varible here
filterPosts: function ($someData) {
this.total += parseInt(this.$el.dataset.value);
}