Home > Web Front-end > JS Tutorial > How to add mobile contacts in WeChat mini program

How to add mobile contacts in WeChat mini program

亚连
Release: 2018-06-23 15:32:05
Original
2965 people have browsed it

This article mainly introduces the function of adding mobile phone contacts in the WeChat applet, and analyzes the specific steps of adding contacts in the WeChat applet in the form of examples, including layout and logic implementation skills. Friends in need can refer to the following

The example in this article describes the WeChat applet to implement the function of adding mobile phone contacts. Share it with everyone for your reference, the details are as follows:

1. Effect display

2. Key code

1) WXML file

<view bindlongtap="phoneNumTap">{{phoneNum}}</view>
Copy after login

2) JS file

Page({
 data:{
 phoneNum:&#39;12345678901&#39;//测试用的号码,并非真实号码
 },
 // 长按号码响应函数
 phoneNumTap:function(){
 var that=this;
 // 提示呼叫号码还是将号码添加到手机通讯录
 wx.showActionSheet({
  itemList: [&#39;呼叫&#39;,&#39;添加联系人&#39;],
  success:function(res){
  if(res.tapIndex===0){
   // 呼叫号码
   wx.makePhoneCall({
   phoneNumber: that.data.phoneNum,
   })
  }else if(res.tapIndex==1){
   // 添加到手机通讯录
   wx.addPhoneContact({
   firstName: &#39;test&#39;,//联系人姓名
   mobilePhoneNumber: that.data.phoneNum,//联系人手机号
   })
  }
  }
 })
 }
})
Copy after login

3) WXSS file

view{
 color: blue;
 padding: 15px;
 border-bottom: 1px solid gainsboro;
}
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

About the loop mechanism of js events (detailed tutorial)

How to use javascript to implement QQ space photo album display

How to customize PC WeChat scan code login

Details about the use of jade template engine

Related JS Hill sorting algorithm (detailed tutorial)

The above is the detailed content of How to add mobile contacts in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template