You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向client:load加载的React组件传递点击事件处理函数无效的问题咨询

向client:load加载的React组件传递点击事件处理函数无效的问题咨询

各位好,我遇到一个 Astro 开发里的问题,卡了好一会儿,想请教下大家:

我在 index.astro 里写了下面这段代码,想给用 client:load 加载的 Button 组件绑定点击事件,但是点击完全没反应:

const handleClick = () => console.log("clicked");
---
<Button client:load onClick={handleClick}>bla</Button>

这个 Button 组件是用的 Shadcn 的组件。我打开浏览器里的 Astro 开发者工具,看到组件的 props 里 onClick 居然是 null:

{
  "onClick": null
}

我之前知道 Astro 里可以把前置脚本(front matter)里的变量传递给框架组件的 props,但为啥函数就不行呢?有没有大佬能帮忙解释下原因,或者告诉我该怎么解决这个问题呀?

备注:内容来源于stack exchange,提问作者timebandit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 15:28:08