微信小程序错误 Cloud API isn‘t enabled, please call wx.cloud.init first 解决
生活随笔
收集整理的這篇文章主要介紹了
微信小程序错误 Cloud API isn‘t enabled, please call wx.cloud.init first 解决
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Cloud API isn't enabled, please call wx.cloud.init first 這個錯誤的意思就是云環境還沒有初始化就調用其它的云api了,因此需要先初始化,也就是讓我們先 wx.cloud.init() 進行初始化,最簡單的辦法就是直接在最前面初始化,代碼如下:(只需要關注第3~9行即可)
import User from './model/user' import $ from './utils/tool'//請關注下面的,上面兩行與該問題無關 wx.cloud.init({env: 'zaiyi-3ggp5zmqe2dd21e7', //填上你的云開發環境idtraceUser: true, }) const db = wx.cloud.database() //請關注上面的,下面與該問題無關App({initUiGlobal() {return new Promise(resolve => {wx.getSystemInfo({success: e => {this.globalData.StatusBar = e.statusBarHeightthis.globalData.screenHeight = e.screenHeightconst capsule = wx.getMenuButtonBoundingClientRect()if (capsule) {this.globalData.Custom = capsulethis.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight} else {this.globalData.CustomBar = e.statusBarHeight + 50}},complete: resolve})})},async login() {$.loading()const user = new User()wx.cloud.callFunction({name: 'getOpenid', // 對應云函數名complete: res => {console.log(res.result.event.userInfo.openId)this.globalData.openid = res.result.event.userInfo.openIddb.collection('user').where({_openid:res.result.event.userInfo.openId}).get().then(res => {console.log(res.data.length)if(res.data.length == 0){user.register()}})}})$.hideLoading()},async onLaunch() {await this.initUiGlobal()this.login()},globalData: {StatusBar: null,Custom: null,CustomBar: null,screenHeight: null,env: 'zaiyi-3ggp5zmqe2dd21e7',openid: ''} })總結
以上是生活随笔為你收集整理的微信小程序错误 Cloud API isn‘t enabled, please call wx.cloud.init first 解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓时代历史相似指的是哪方面(安卓时代)
- 下一篇: linux返回上一层命令(linux返回