使用 Riot.js 的服务器端呈现:在标记中将 opts.foo 传递给 this.foo

Server side rendering with Riot.js: Passing opts.foo to this.foo in tag

我在使用 Riot 进行服务器端渲染时遇到问题。

在我的处理程序中,我将我的 foo 对象传递到我的 bar 标记中,其中包含与此非常相似的内容:

reply(riot.render(bar, { foo: foo }));

这是我的简单条形标签的副本:

<bar>
    <h1>TEST</h1>
    <h1>{ foo }</h1>

    this.foo = opts.foo
    console.log(this.foo)
</bar>

当我将浏览器指向相关路径时,'TEST' 可见但 foo 不可见。我的 console.log(foo) 工作正常。

这对我的类似设置有用

<bar>
    <h1>TEST</h1>
    <h1>{ opts.foo }</h1>
    console.log(opts.foo)
</bar>

我认为最好直接绑定到数据对象而不是将其设置为另一个局部变量