admin管理员组文章数量:1394611
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()
本文标签: javascriptCall function within function of AlpineJSStack Overflow
版权声明:本文标题:javascript - Call function within function of AlpineJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744095863a2590271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论