javascript - Call function within function of AlpineJS - Stack Overflow

In the AlpineJS docs there's this example:<div x-data="dropdown()"><button x-on

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
Add a ment  | 

1 Answer 1

Reset to default 5
dropdown().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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信