我有一个应用程序,我想控制什么时候重新绘制视图。
我可以用m.mount和m.redraw让它工作
var count = 0;
var Counter = {
view: function() {
return m('main', [
m('h1', ('Count: ' + count))
])
}
}
m.mount(document.body, Counter);
window.setInterval(function () {
count++;
m.redraw();
}, 200);<html>
<body>
<script src="https://unpkg.com/mithril/mithril.js"></script>
<script src="index.js"></script>
</body>
</html>
但是,如果我使用m.render (因为我不需要mithril自动重新绘制),它就不再工作了:
var count = 0;
var Counter = {
view: function() {
return m('main', [
m('h1', ('Count: ' + count))
])
}
}
m.render(document.body, m(Counter)); // <-- The only changed line
window.setInterval(function () {
count++;
m.redraw();
}, 200);<html>
<body>
<script src="https://unpkg.com/mithril/mithril.js"></script>
<script src="index.js"></script>
</body>
</html>
当使用m.render而不是m.mount时,如何使mithril重绘
发布于 2017-09-14 09:36:49
正如mithril文档中所述的那样,这里:
注意,
m.redraw只在使用m.mount或m.route时才能工作。如果您通过m.render呈现,则应该使用m.render重绘。
var count = 0;
var Counter = {
view: function() {
return m('main', [
m('h1', ('Count: ' + count))
])
}
}
m.render(document.body, m(Counter));
window.setInterval(function () {
count++;
m.render(document.body, m(Counter)); // <-- Use m.render here, not m.redraw
}, 200);<html>
<body>
<script src="https://unpkg.com/mithril/mithril.js"></script>
<script src="index.js"></script>
</body>
</html>
https://stackoverflow.com/questions/46215561
复制相似问题