起因是新建了一个云对象,里面有两个方法,获取简易和复杂字段。在一个store中调用复杂方法没问题,在后续编写另一个store并且调用简易方法时出现ReferenceError: uniCloud is not defined,后面试过新建一个云函数重做简易方法,但是调用依旧是uniCloud is not defined。

起因是新建了一个云对象,里面有两个方法,获取简易和复杂字段。在一个store中调用复杂方法没问题,在后续编写另一个store并且调用简易方法时出现ReferenceError: uniCloud is not defined,后面试过新建一个云函数重做简易方法,但是调用依旧是uniCloud is not defined。

阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程
** Issue 解决方案 **
根据你的描述,uniCloud is not defined 是因为在另一个 Store 中,uniCloud 这个对象没有被引入导致的。
建议的解决方案是:
核心代码:
import uniCloud from uniCloud
核心代码:
// main.js
import uniCloud from uniCloud
uniCloud.init({
// ...
})
核心代码:
// store.js
export default {
beforeCreate() {
// 检测是否初始化成功
if (! uniCloud.isInitialized()) {
uniCloud.init({
// ...
})
}
},
}