我使用Hyperstack.org的安装说明基本安装了一个超级堆栈rails应用程序,试图在一个HTTP.get回调中添加一个after_mount请求。
不太确定我还能尝试什么,认为HTTP将是一个标准的选项
class App < HyperComponent
include Hyperstack::Router
after_mount do
HTTP.get('/example.json')
end
render do
DIV() do
'App'
# NodeDisplay
# define routes using the Route psuedo component. Examples:
# Route('/foo', mounts: Foo) : match the path beginning with /foo and mount component Foo here
# Route('/foo') { Foo(...) } : display the contents of the block
# Route('/', exact: true, mounts: Home) : match the exact path / and mount the Home component
# Route('/user/:id/name', mounts: UserName) : path segments beginning with a colon will be captured in the match param
# see the hyper-router gem documentation for more details
end
end
end收到的错误是:
Uncaught error: HTTP: uninitialized constant App::HTTP
in App (created by Hyperstack::Internal::Component::TopLevelRailsComponent)
in Hyperstack::Internal::Component::TopLevelRailsComponent发布于 2019-09-08 02:33:05
简单的回答:默认情况下,Opal或Hyper堆栈中不包含HTTP库。
您可以将其作为Opal jQuery包装器的一部分,或者使用最小的Opal Browser::HTTP库。
要将包装器添加到您的超级堆栈应用程序中,请执行以下操作:
import 'hyperstack/component/jquery', client_only: true
到您的config/initializers/hyperstack.rb文件。如果使用webpacker,请在终端中运行yarn add jquery,然后将这一行添加到javascripts/packs/client_only.js文件中:jQuery = require('jquery');
如果不使用,则使用webpacker将import 'jquery', client_only: true添加到超级堆栈初始化文件中。
如果您只想使用最小的Browser::HTTP 模块,那么添加
import 'browser/http到您的config/initializers/hyperstack.rb文件。 更改hyperstack.rb后,您必须通过运行rm -rf tmp/cache清除rails tmp缓存。 注意:在使用浏览器版本时,您需要使用Browser::HTTP而不是简单的HTTP__。
https://stackoverflow.com/questions/57838479
复制相似问题