小编Irf*_*fan的帖子

How to access a property or a method of alpine.js parent component from a child component?

This is kind of an example scenario what the problem looks like,

<div x-data="{ count : 0 }">
    <div x-data>
        <span x-text="count"></span>
        <button x-on:click="count++">Increment</button>
        <button x-on:click="count--">Decrement</button>         
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

It would be able to increase/decrease the data count from the child component. I thought of handling it through dispatching custom events using $dispatch() but then again in terms of design, I might need to write listeners on both parent and child component which make the logic more complex since it should …

javascript alpine.js

3
推荐指数
1
解决办法
4384
查看次数

标签 统计

alpine.js ×1

javascript ×1