html5创建手机通讯录代码,uni 您所在的位置:网站首页 html5获取手机通讯录 html5创建手机通讯录代码,uni

html5创建手机通讯录代码,uni

2023-09-11 05:48| 来源: 网络整理| 查看: 265

官方API:https://www.html5plus.org/doc/zh_cn/contacts.html

话不多说,直接上代码

contacts.vue

获取联系人

{{item.displayName}}

{{subitem.value}}

var Contacts

export default {

data() {

return {

list: []

}

},

onShow() {

uni.setNavigationBarTitle({

title: '通讯录'

});

},

methods: {

getContacts: function() {

var that = this

// 获取通讯录对象

plus.contacts.getAddressBook( plus.contacts.ADDRESSBOOK_PHONE, function( addressbook ) {

uni.showToast({

title: '获取通讯录对象成功',

duration: 2000

})

console.log('获取通讯录对象成功')

console.log(addressbook)

// 查找联系人

addressbook.find(["displayName","phoneNumbers"],function(contacts){

uni.showToast({

title: '获取联系人成功',

duration: 2000

})

console.log('获取联系人成功')

console.log(JSON.stringify(contacts))

that.list = contacts

}, function () {

uni.showToast({

title: '获取联系人失败',

duration: 2000

})

},{multiple:true});

}, function ( e ) {

uni.showToast({

title: '获取通讯录对象失败:' + e.message,

duration: 2000

})

});

}

}

}

注:由于hx调试输出console.log()不能直接输出对象,故用JSON.stringify()转一下,好作调试输出。示意:console.log(JSON.stringify(contacts))



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有