Ruby 关于 Stimulus 的 action 使用问题

july_12 · April 19, 2024 · Last by july_12 replied at April 19, 2024 · 243 hits

我在 hotwire官网介绍视频中看到,作者在使用 stimulus 来处理表单提交后的清空操作。

看了之后有个疑惑,关于 action 的设置:

作者的 code 是下面的写法


action: "turbo:submit-end->reset-form#clear"

可我在 stimulus action 文档中并没有看到该写法的介绍。

发现采用下面的写法,也能正常工作。


action: "submit->reset-form#clear"

我比较好奇这两种方式有啥区别吗?各基于什么场景下使用。

直接参考 Stimulus 官方 Reference (Action 章节)

https://stimulus.hotwired.dev/reference/actions

data-action: "DOM_Event名称->控制器名称#method 名称"

turbo:submit-end 事件

参考 https://turbo.hotwired.dev/reference/events

Reply to 1c7

感谢,这下明白了。

You need to Sign in before reply, if you don't have an account, please Sign up first.