Skip to content

ContactList - Vant 4

ContactList

Intro

Used to display the contact list.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { ContactList } from'vant'; const app = createApp(); app.use(ContactList);

Usage

Basic Usage

html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const chosenContactId = ref('1'); const list = ref([ { id: '1', name: 'John Snow', tel: '13000000000', isDefault: true, }, { id: '2', name: 'Ned Stark', tel: '1310000000', }, ]); constonAdd = () => showToast('Add'); constonEdit = (contact) => showToast('Edit' + contact.id); constonSelect = (contact) => showToast('Select' + contact.id); return { list, onAdd, onEdit, onSelect, chosenContactId, }; }, };

API

Props

AttributeDescriptionTypeDefault
v-modelId of chosen contact*numberstring*
listContact listContactListItem[][]
add-textAdd button textstringAdd new contact
default-tag-textDefault tag textstring-

Events

EventDescriptionArguments
addEmitted when the add button is clicked-
editEmitted when the edit button is clickedcontact: ContactListItem, index: number
selectEmitted when a contact is selectedcontact: ContactListItem, index: number

Data Structure of ContactListItem

keyDescriptionType
idID*number
nameNamestring
telPhonestring
isDefaultIs default contact*boolean

Types

The component exports the following type definitions:

ts
importtype { ContactListItem, ContactListProps } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-contact-list-paddingvar(--van-padding-sm) var(--van-padding-sm) 80px-
--van-contact-list-edit-icon-size16px-
--van-contact-list-add-button-z-index999-
--van-contact-list-radio-colorvar(--van-primary-color)-
--van-contact-list-item-paddingvar(--van-padding-md)-

Enterprise-level mobile solution based on Vant