问题代码(报错)
// pages/cart/cart.uvue
<script setup lang="uts">
import { ref, computed, onMounted } from 'vue'
const loadCartList = () => {
const userInfo = JSON.parse(JSON.stringify(uni.getStorageSync('userInfo'))) as UTSJSONObject
const userId = userInfo._id as string
const callOptions: any = {
name: 'cart-list',
data: { userId: userId },
success: (res: any) => { /* ... */ },
fail: () => { /* ... */ }
}
(uniCloud as any).callFunction(callOptions) // ❌ 报错:找不到名称"callFunction"
}
</script>
对比代码(正常)
// pages/login/login.uvue - 相同的代码模式,可以正常编译
<script setup lang="uts">
import { ref } from 'vue'
const handleLogin = () => {
const callOptions: any = {
name: 'user-login',
data: { phone: phone.value, password: password.value },
success: (res: any) => { /* ... */ },
fail: () => { /* ... */ }
}
(uniCloud as any).callFunction(callOptions) // ✅ 正常编译
}
</script>
已尝试的解决方案(均失败)
- ✅ 使用
callOptions 变量(与正常文件相同)
- ✅ 使用内联对象字面量
- ✅ 使用辅助函数包装
- ✅ 使用括号访问
cloud['callFunction']
- ✅ 清理编译缓存
- ✅ 改为箭头函数
影响范围
- 受影响文件:
pages/cart/cart.uvue
- 其他文件:
pages/login/login.uvue、pages/index/index.uvue、pages/sell/sell.uvue 等使用相同模式的文件均正常