当使用带有 ecmascript 箭头符号的流星时,使用“this”访问文档中描述的值总是失败。例如:
Template.temp.onCreated(()=> {
this.var = new ReactiveVar("")
})
然后通过以下方式访问它:
Template.instance().var
总是失败。这在流星、客户端或服务器端几乎任何使用“this”的情况下都是一致的。从客户端检查时,我可以看到“this”被编译成“_this”,这总是导致代码失败。
代码编译成:
_this = this
Template.temp.onCreated(function() {
_this.var = new ReactiveVar("")
})
任何建议表示赞赏。