Home >WeChat Applet >Mini Program Development >How do we implement the WeChat mini program dialing function?

How do we implement the WeChat mini program dialing function?

王林
王林forward
2020-12-30 16:44:334127browse

How do we implement the WeChat mini program dialing function?

Foreword:

Since the click thing here is a picture, we need to set up a view first, and the bindtap event is used here.

(Learning video sharing: Programming video)

First of all, let’s take a look at what the official document says:

How do we implement the WeChat mini program dialing function?

The code of my demo is like this

index.wxml

<view bindtap=&#39;tel&#39;>
<image class=&#39;tel&#39; mode=&#39;aspectFit&#39; src=&#39;./img/tel.png&#39;></image>
</view>

Then adjust the ss. Of course, this is just my demo. The actual application depends on the actual application.

index.wxss

.tel{
  display: block;
  width: 70rpx;
  height: 70rpx;
  position: absolute;
  margin-top:-100rpx;
  margin-left: 200rpx; 
}

Directly call the call API wx.makePhoneCall(OBJECT)

The official documentation is also very clear

How do we implement the WeChat mini program dialing function?

Mainly fill in the phoneNumber, others depend on the needs.

The first method is: add

tel:function () {
  wx.makePhoneCall({
    phoneNumber: &#39;158XXXXXXXX&#39;,
  })
}

in the Page of

index.js. There is another way Yes:

Just go to the global variable to set it, go to the globalData of the outermost app.js and add

globalData: {
  userInfo: null,
  phoneNumber: &#39;158XXXXXXXX&#39;
}

and then index.js adds

tel:function () {
  wx.makePhoneCall({
    phoneNumber: app.globalData.phoneNumber,
  })
}

and click Save

How do we implement the WeChat mini program dialing function?

Related recommendations:小program development tutorial

The above is the detailed content of How do we implement the WeChat mini program dialing function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete