alpine.js - 将 AlpineJS 点击事件附加到刀片组件
问题描述
我需要一个刀片组件来发出一个 AlpineJS 点击事件,以便在多个地方使用它。我做了一些测试,但我无法让它工作。
这工作正常:
<div x-data="{open:false}">
<button x-on:click.window="open = true">Open</button>
<div x-show="open">
<div style="width: 100px; height: 100px; background-color: #0a6ebd; border-radius: 15px;">
</div>
</div>
但是,如果我将按钮包装在刀片组件中,我就不工作了:
<div x-data="{open:false}">
<x-my-button x-on:click.window="open = true"></x-my-button>
<div x-show="open">
<div style="width: 100px; height: 100px; background-color: #0a6ebd; border-radius: 15px;">
</div>
</div>
刀片组件是按钮:
<button>Open</button>
如何向父级发出点击事件?
解决方案
只需要将 $attributes 传递给刀片组件:
<button {{$attributes}}>Open</button>
推荐阅读
- c# - 使用在 try 中声明的变量 使用 catch 中的值
- java - 即使 fetchtype 是惰性的,JPA 也会加载太多数据
- javascript - 在angularjs中突出显示html字符串中的多个文本
- ms-access - 使用 Access 数据源在 PowerBI 上自动计划报告
- kubernetes - 如何修补 Kubernetes 上已部署的 Ingress 资源?
- python - align 返回元组而不是 Pandas DataFrame
- vb.net - 我的程序无法从 TCP 连接读取 ASCII 字符串,不断循环
- php - 多个facebook喜欢的核心php页面计数
- linux - 如何更改 Linux USB 复合小工具的功能?
- .net-core - 从 identityserver4 中的 PersistedGrantStore 密钥属性获取刷新令牌