首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在超级堆栈中使用HTTP

如何在超级堆栈中使用HTTP
EN

Stack Overflow用户
提问于 2019-09-08 01:04:22
回答 1查看 52关注 0票数 0

我使用Hyperstack.org的安装说明基本安装了一个超级堆栈rails应用程序,试图在一个HTTP.get回调中添加一个after_mount请求。

不太确定我还能尝试什么,认为HTTP将是一个标准的选项

代码语言:javascript
复制
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

收到的错误是:

代码语言:javascript
复制
Uncaught error: HTTP: uninitialized constant App::HTTP
in App (created by Hyperstack::Internal::Component::TopLevelRailsComponent)
in Hyperstack::Internal::Component::TopLevelRailsComponent
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-08 02:33:05

简单的回答:默认情况下,Opal或Hyper堆栈中不包含HTTP库。

您可以将其作为Opal jQuery包装器的一部分,或者使用最小的Opal Browser::HTTP库。

要将包装器添加到您的超级堆栈应用程序中,请执行以下操作:

  1. 通过添加 import 'hyperstack/component/jquery', client_only: true 到您的config/initializers/hyperstack.rb文件。
  2. 然后在资产中包含实际的jquery javascript代码:

如果使用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__。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57838479

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档