在Mithril.js中(使用webpack),我需要将vnode传递给匿名函数:
怎么做?
var Button = {
view:function(vnode){
return m('div',{onclick:(vnode)=> setSort(vnode)})
}
}
function setSort(vnode){
.... do somthing with vnode ....
}
答案 0 :(得分:2)
Event handlers get passed the event
object, not a vnode
. You already have access to the vnode
via closures, it's passed to your view
method as the first argument.
const Button = {
view(vnode) {
return m("button", {
onclick() {
console.log(vnode);
}
}, "Button");
}
};
m.mount(document.body, {
view() {
return m("div",
m(Button)
);
}
});
Here's a running example on flems.io.