<div x-data="dropdown()">
<button x-on:click="open">開啟</button>
<div x-show="isOpen()" x-on:click.away="close">
<div>下拉選單內容</div>
</div>
</div>
function dropdown() {
return {
show: false,
open() { this.show = true },
close() { this.show = false },
isOpen() { return this.show === true },
}
}
This Pen doesn't use any external CSS resources.