Pab*_*eda 4 namespaces symfony stimulusjs
早上好。我在遵循 Stimulus 文档中指定的名称约定的 Stimulus 控制器和命名空间方面遇到问题。
当我像这样使用我的控制器时,一切都会按预期工作:
/controllers/gifts_controller.js
data-controller="gifts"
如果我以这种方式使用控制器,则没有任何效果:
/controllers/frontend/gifts_controller.js
data-controller="frontend--gifts"
Stimulus 文档指定子文件夹中控制器的名称约定必须与第二个示例类似,但它不起作用。没有错误,就像不存在一样。
有任何想法吗?
编辑:抱歉我写错了
文件名中的后缀_controller.js是 Stimulus 用于检索目录结构中的控制器的约定。它不应包含在data-controller属性中。
正如您共享的文档文章中所述:
\nName your controller files [identifier]_controller.js, where [identifier] corresponds\nto each controller\xe2\x80\x99s data-controller identifier in your HTML.\nRun Code Online (Sandbox Code Playgroud)\n双破折号 ( --) 替换/命名空间(子文件夹)结构中的任何正斜杠 ( )。
在您的情况下,文件的controllers/frontend/gifts_controller.js标识符为frontend--gifts。\n因此,在 HTML 元素的 data 属性中,您应该将控制器称为data-controller="frontend--gifts"。
| 归档时间: |
|
| 查看次数: |
2922 次 |
| 最近记录: |