<view class="index">
<button type="primary" @tap="getContacts" style="padding: 20rpx 0;">获取联系人</button>
<block v-for="(item,index) in list" :key="index">
<view>{{item.displayName}}</view>
<block v-for="(subitem,idx) in item.phoneNumbers" :key="idx">
<view>{{subitem.value}}</view>
</block>
</block>
</view>
var Contacts //export default 前
uni.setNavigationBarTitle({
title: '修改头部的title'
});
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
})
});
}