经过自己不断的努力终于解决了这个问题,在网上找了一圈都没有找到。。。
主要实现功能为:云开发中储存的店铺手机号码,通过js从数据库中获取后,利用wx.makePhoneCall跳转拨打电话界面,实现结果很完美。在这里写一个笔记,供自己以后使用,有需要的小伙伴可以借鉴。方法仅供参考,本人小白一枚,勿喷。。。
遇到js问题,多查看官方文档:https://zixuephp.net/manual-javascript-658.html
代码如下:
//wxml代码
<button class="button_phone" bindtap="_calling">
<image src="../../../images/icon/phone.png" mode="aspectFit"/>
</button>
//js代码
/**
*从数据库中获取店铺手机号码
*/
const db = wx.cloud.database()
db.collection('shop_information').get({
success:res=> {
console.log(res)
this.setData({
//将从云端获取的数据放到shop_info中
shop_info: res.data,
phoneNumber:res.data[0].phone
})
},
fail: console.error
})
/**
*小程序跳转电话界面
*/
_calling:function(evt){
// this.setData({
// phoneNumber:this.data.phoneNumber
// })
wx.makePhoneCall({
phoneNumber: this.data.phoneNumber //phoneNumber定义为字符串string
})
},
效果图如下:

2.jpg

1.jpg