【问题标题】:Attach AlpineJS click event to blade component将 AlpineJS 点击事件附加到刀片组件
【发布时间】:2021-08-04 15:19:03
【问题描述】:

我需要一个刀片组件来发出一个 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>

如何向父级发送点击事件?

【问题讨论】:

    标签: alpine.js


    【解决方案1】:

    只需将 $attributes 传递给刀片组件:

     <button {{$attributes}}>Open</button> 
    

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      相关资源
      最近更新 更多