正如您在测试中看到的那样,当重绘“p”内容时,会更新“p”内容而不是与源具有相同数据流的输入值。为什么呢?
var root = document.body
let v = m.stream({
field: m.stream()
})
var Hello = {
view: function() {
return m("main", [
m("input", {
value: v().field(),
oninput: m.withAttr('value', v().field)
}),
m(
'p', [
v().field()
]
),
m(
"button", {
"type": "button",
onclick: function() {
v({
field: m.stream()
})
}
}, [
'save'
]
),
m('div', ['Write on input then click save. After click save the P content disappear but input value still. why?'])
])
}
}
m.mount(root, Hello)
<script src="https://unpkg.com/mithril/mithril.js"></script>
<script src="https://unpkg.com/mithril-stream"></script>