好像不支持uni-cloud-router的,于是我做了个demo,如下架构。
|-- backend
|-- index.obj.js
|-- package.json
|-- module
|-- user
|-- index.js
在用户模块module/user/index.js中写了个hello
方法,一会儿去前端调用
// module/user/index.js
module.exports = {
hello() {
return 'hello'
}
}
入口文件是index.obj.js
,引入刚才的用户模块
// index.obj.js
let user = require('./module/user')
module.exports = {
// 通用预处理器
_before: function() {
},
// 暴露出来
user
}
在前端页面中调用hello方法
// pages/index/index.vue文件 引入我的云对象,名称是backend
let co = uniCloud.importObject('backend')
export default {
onLoad() {
// TypeError: co.user.hello is not a function
co.user.hello()
}
}
调用会报错 TypeError: co.user.hello is not a function
,有朋友知道怎么实现云对象中逻辑模块的隔离方案吗?不如不隔离的话,在一个项目中往往有大量的接口,需要全部在index.obj.js
中暴露吗?
呆狗的一生 (作者)
知道了,谢谢解答
2022-09-27 18:57