如何使用铁轨导入地图的刺激组件

发布于 2025-01-26 20:26:05 字数 1152 浏览 5 评论 0原文

我想将此刺激组件包括在我的全新Rails 7应用中: https://www.stimulus-components.com/docs/docs/docs/docs/stimulus-dropdown

当我遵循他们的设置方法时,我会在浏览器控制台中获得以下错误: 平台#:1 Undpref TypeError:未能解析模块指定符“ impoinus-dropdown”。相对引用必须以“/”,“ ./”或“ ../”开头。

我在Stackoverflow上找到了这篇文章: 未能解决模块指定器“ stimulus-autocomplete

”我的importmap.rb的“销钉”。

因此,我从此处获取了下拉链接 https://wwww.jsdelivr.com/ppackage/ppackage/npm n. /imporulus-dropdown

并将其放入我的importmap.rb中:

pin "stimulus-dropdown", to: "https://cdn.jsdelivr.net/npm/[email protected]/dist/stimulus-dropdown.min.js"

但是它不起作用,并且在我的浏览器控制台中显示404。

我希望有人可以提供帮助,必须有一种简单的方法来在全新的Rails 7应用程序中使用刺激组件。

I want to include this stimulus component into my brand new rails 7 app:
https://www.stimulus-components.com/docs/stimulus-dropdown

When I follow their setup approach, i get the following error in my browser console:
platforms#:1 Uncaught TypeError: Failed to resolve module specifier "stimulus-dropdown". Relative references must start with either "/", "./", or "../".

I found this article on stackoverflow:
Failed to resolve module specifier "stimulus-autocomplete"

which suggests to add a "pin" to my importmap.rb.

So i took the dropdown link from here https://www.jsdelivr.com/package/npm/stimulus-dropdown

and put it into my importmap.rb by:

pin "stimulus-dropdown", to: "https://cdn.jsdelivr.net/npm/[email protected]/dist/stimulus-dropdown.min.js"

But it doesnt work and displays a 404 in my browser console.

I hope someone can help, there must be an easy way to use stimulus-components in a brand new rails 7 app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风筝有风,海豚有海 2025-02-02 20:26:05

我也很挣扎,但我已经弄清楚了它是

第一次运行 -

./bin/importmap pin stimulus-dropdown

第二个创建一个名为“下拉'”的刺激控制器 -

rails g stimulus dropdown

然后在完成所有上述所有操作后,将以下代码复制到下拉列表中

import { Application } from '@hotwired/stimulus'
 import Dropdown from 'stimulus-dropdown'

 const application = Application.start()
 application.register('dropdown', Dropdown)

,您可以使用刺激下拉列表你的
视图。有关查看示例,请检查网站上的文档。

i was also struggling but i have figured it out

first run -

./bin/importmap pin stimulus-dropdown

second create a stimulus controller called 'dropdown' -

rails g stimulus dropdown

then copy-paste the following code into the dropdown controller

import { Application } from '@hotwired/stimulus'
 import Dropdown from 'stimulus-dropdown'

 const application = Application.start()
 application.register('dropdown', Dropdown)

After you do all the above you are ready to use stimulus drop-down in your
views. for the view example check the docs on the site.

原谅我要高飞 2025-02-02 20:26:05

我建议在YARN上添加它,并在纱线添加signulus-dropdown中添加它。当我面对您的问题时,这对我有用。

I suggest adding it with yarn as well with yarn add stimulus-dropdown. This worked for me when I faced your issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文