我正在使用<template>
<div>
Test2
<button @click="testFunction">click me</button>
</div>
</template>
<script>
export default {
data() {
return {
testFunction: null,
value: "Test2"
};
},
created() {
this.testFunction = this.aFunction.bind(this);
},
props: {
aFunction: {
required: true,
type: Function
}
}
};
</script>
和lodash
来检索数据,看起来像这样:
mobx
工作正常,但是在_.get(store, "prop.arr[0].subProp")
为mobx
或为空的情况下,arr
会给我警告:
undefined
有什么解决方法吗?我不想添加长度检查,而是希望将其保持为单线。
答案 0 :(得分:2)
在将store
传递到get
之前,先由mobx传递toJS
实用程序。这应该可以解决。
所以您的班轮号码是-_.get(toJS(store), "prop.arr[0].subProp")
这里toJS
的更多信息-https://mobx.js.org/refguide/tojson.html