跳转至

$root

$root 是一个魔术属性,用于获取任何 Alpine 组件的根元素。换句话说,就是 DOM 树中最近的一个包含 x-data 的元素。

<div x-data data-message="Hello World!">
    <button @click="alert($root.dataset.message)">Say Hi</button>
</div>