x-ref
x-ref 与 $refs 结合使用,是一个有用的工具,用于直接访问 DOM 元素。它最常作为 getElementById 和 querySelector 等 API 的替代方案。
<button @click="$refs.text.remove()">Remove Text</button>
<span x-ref="text">Hello 👋</span>
Hello 👋
尽管上述代码片段中没有包含,但如果没有父元素定义
x-data,则无法使用x-ref。→ 阅读更多关于x-data