我試圖在智能組件中觸發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'可能在'onMount'範圍內是未定義的。 – Razzildinho
@Razzildinho更新! –
@Razzildinho它似乎沒有在客戶端找到模塊。 –