【发布时间】:2017-04-04 22:53:35
【问题描述】:
我正在尝试在我的智能组件中触发onMount 时呈现组件。服务器似乎可以正确渲染组件,但是当在客户端触发 onMount 时它不会渲染,我得到一个简单的 undefined。
const button = require('src/client/components/a-button');
console.log(button); // --> { path: '/home/karl/dev/instanty/node/src/client/components/a-button.marko.js', _: [Getter/Setter], '$__shouldBuffer': true, meta: {} }
const htmlServer = button.renderToString({ label: 'Click me!' }); // <-- works
console.log(htmlServer);
module.exports = class {
onMount() {
console.log(button); // --> Template {path: undefined, meta: undefined, _: function}
const html = button.renderToString({ label: 'Click me!' }); // <-- does not work
console.log(html);
}
//... more code
}
我需要此处所述的组件:http://markojs.com/docs/rendering/#rendering
我也在使用套索,我怀疑这可能是它不起作用的原因。我怀疑套索没有捆绑组件并将其发送给客户端。
我还阅读了以下内容:http://markojs.com/docs/lasso/#client-side-rendering
【问题讨论】:
-
你能
console.log(button)吗?常量是块作用域的,所以button可能在onMount作用域中未定义。 -
@Razzildinho 更新了!
-
@Razzildinho 客户端好像没找到模块。
标签: javascript marko