In the AlpineJS docs there's this example:
<div x-data="dropdown()">
<button x-on:click="open()">Open</button>
<div x-show="isOpen()" x-on:click.away="close()">
// Dropdown
</div>
</div>
<script>
function dropdown() {
return {
show: false,
open() { this.show = true },
close() { this.show = false },
isOpen() { return this.show === true },
}
}
</script>
Now what I would like to do is within that <script>
have another function that calls close()
, so something like:
function aNewFunction()
{
close();
}
In the AlpineJS docs there's this example:
<div x-data="dropdown()">
<button x-on:click="open()">Open</button>
<div x-show="isOpen()" x-on:click.away="close()">
// Dropdown
</div>
</div>
<script>
function dropdown() {
return {
show: false,
open() { this.show = true },
close() { this.show = false },
isOpen() { return this.show === true },
}
}
</script>
Now what I would like to do is within that <script>
have another function that calls close()
, so something like:
function aNewFunction()
{
close();
}
Share
Improve this question
asked Mar 9, 2020 at 13:49
eskimoeskimo
2,6358 gold badges52 silver badges98 bronze badges
1 Answer
Reset to default 5dropdown().close
This will return close() if you want to call close then simply do something like this .
dropdown().close()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744095863a4557931.html
评论列表(0条)