微信小程序错误 Cloud API isn‘t enabled, please call wx.cloud.init first 解决
生活随笔
收集整理的這篇文章主要介紹了
微信小程序错误 Cloud API isn‘t enabled, please call wx.cloud.init first 解决
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Cloud API isn't enabled, please call wx.cloud.init first 這個(gè)錯(cuò)誤的意思就是云環(huán)境還沒有初始化就調(diào)用其它的云api了,因此需要先初始化,也就是讓我們先 wx.cloud.init() 進(jìn)行初始化,最簡(jiǎn)單的辦法就是直接在最前面初始化,代碼如下:(只需要關(guān)注第3~9行即可)
import User from './model/user' import $ from './utils/tool'//請(qǐng)關(guān)注下面的,上面兩行與該問題無(wú)關(guān) wx.cloud.init({env: 'zaiyi-3ggp5zmqe2dd21e7', //填上你的云開發(fā)環(huán)境idtraceUser: true, }) const db = wx.cloud.database() //請(qǐng)關(guān)注上面的,下面與該問題無(wú)關(guān)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', // 對(duì)應(yīng)云函數(shù)名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: ''} })總結(jié)
以上是生活随笔為你收集整理的微信小程序错误 Cloud API isn‘t enabled, please call wx.cloud.init first 解决的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓时代历史相似指的是哪方面(安卓时代)
- 下一篇: 微信小程序云开发小项目“研岸日记”日记记