AddressList — 주소 목록
주소록을 보여 주고 관리하는 컴포넌트예요. 항목 클릭, 삭제·편집 버튼은 물론 길게 누르기와 오른쪽으로 스와이프 동작까지 지원해서 주소 관리 화면을 빠르게 만들 수 있어요.
소개
주로 주소 목록을 표시하고 다루는 데 사용해요.
설치
import { createApp } from 'vue'
import { AddressList } from '@nutui/nutui'
const app = createApp()
app.use(AddressList)
기본 사용법
:::demo
<template>
<nut-address-list
:data="data"
@click-item="clickItem"
@del-icon="delClick"
@edit-icon="editClick"
:show-bottom-button="false"
:data-options="dataOptions"
>
</nut-address-list>
</template>
<script setup>
import { ref, reactive } from 'vue'
const data = ref([
{
testid: 3,
testaddressName: '姓名',
phone: '123****4567',
defaultAddress: false,
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
},
{
testid: 4,
testaddressName: '姓名',
phone: '123****4567',
defaultAddress: true,
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
}
])
const dataOptions = reactive({
id: 'testid',
addressDetail: 'testaddressDetail',
addressName: 'testaddressName'
})
const clickItem = () => {
console.log('Click To Address')
}
const delClick = () => {
console.log('Click To Delete')
}
const editClick = () => {
console.log('Click To Edit')
}
</script>
:::
길게 누르기 기능
:::demo
<template>
<nut-address-list
:data="data"
long-press
:show-bottom-button="false"
@del-icon="delClick"
@edit-icon="editClick"
@click-item="clickItem"
@long-copy="copyClick"
@long-set="setClick"
@long-del="delClickLong"
:data-options="dataOptions"
>
</nut-address-list>
</template>
<script setup>
import { ref, reactive } from 'vue'
const data = ref([
{
testid: 3,
testaddressName: '姓名',
phone: '123****4567',
defaultAddress: false,
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
},
{
testid: 4,
testaddressName: '姓名',
phone: '123****4567',
defaultAddress: true,
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
}
])
const dataOptions = reactive({
id: 'testid',
addressDetail: 'testaddressDetail',
addressName: 'testaddressName'
})
const clickItem = () => {
console.log('Click To Address')
}
const delClick = () => {
console.log('Click To Delete')
}
const editClick = () => {
console.log('Click To Edit')
}
const copyClick = () => {
console.log('Click To Copy')
}
const setClick = () => {
console.log('Click On Settings')
}
const delClickLong = () => {
console.log('Click To Add')
}
</script>
:::
스와이프 기능
:::demo
<template>
<nut-address-list
:data="data"
swipe-edition
show-bottom-button
@edit-icon="editClick"
@del-icon="delClick"
@click-item="clickItem"
@swipe-del="delClickSwipe"
@add="addAddress"
:data-options="dataOptions"
>
</nut-address-list>
</template>
<script setup>
import { ref, reactive } from 'vue'
const data = ref([
{
testid: 3,
testaddressName: '姓名',
phone: '123****4567',
defaultAddress: false,
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
},
{
testid: 4,
testaddressName: '姓名',
phone: '123****4567',
defaultAddress: true,
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
}
])
const dataOptions = reactive({
id: 'testid',
addressDetail: 'testaddressDetail',
addressName: 'testaddressName'
})
const clickItem = () => {
console.log('Click To Address')
}
const editClick = () => {
console.log('Click To Edit')
}
const delClick = () => {
console.log('Click To Delete')
}
const delClickSwipe = () => {
console.log('Click On DelClickSwipe')
}
const addAddress = () => {
console.log('Click To Add')
}
</script>
:::
API
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| data | Address array | Array | - |
| long-press | Long Press Function | boolean | false |
| swipe-edition | Swipe right | boolean | false |
| show-bottom-button | Whether to show the bottom button | boolean | true |
| data-options | When customizing the key value, set the mapping relationship |
Events
| Event | Description | Arguments | Remark |
|---|---|---|---|
| del-icon | Click the delete icon | event: Event,item | public |
| edit-icon | Click the edit icon | event: Event,item | public |
| click-item | Click on each item in the address list | event: Event,item | public |
| add | Click the Add Address button at the bottom | event: Event | public |
| long-copy | Click the Copy Address button | event: Event,item | Click event under long press function |
| long-set | Click the Set Default button | event: Event,item | Click event under long press function |
| long-del | Click the Delete Address button | event: Event,item | Click event under long press function |
| swipe-del | Default right swipe delete button | event: Event,item | Click event under swipe function |
Slots
AddressList 컴포넌트는 기본적으로 여러 영역으로 나뉘고, 이 영역들이 슬롯으로 정의되어 있어서 필요에 따라 교체할 수 있어요.
| Name | Description | Slots |
|---|---|---|
| item-infos | Address list item name/contact/default one line | { item } |
| item-icon | address list item icon | { item } |
| item-addr | Address list item detailed address | { item } |
| swipe-right | Address list item right swipe area | { item } |
| longpress-btns | Address list item long press to mask content | { item } |
data 배열의 각 항목을 dataOptions 객체 파라미터로 매핑하기
아래는 data 배열의 각 항목에 대한 기본 데이터 구조예요.
const dataInfo = {
id: 2, //地址id
addressName: '姓名', //地址姓名
phone: '123****4567', //联系方式
defaultAddress: false, //是否是默认
fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试' //详细地址
}
컴포넌트는 기본 데이터 구조에 정의된 필드를 우선 사용해요. key 값을 커스터마이즈하고 싶다면 dataOptions로 매핑 관계를 설정할 수 있어요.
const dataOptions = {
id: 'testid',
addressDetail: 'testaddressDetail',
addressName: 'testaddressName'
}
테마 (Theming)
CSS 변수
이 컴포넌트는 스타일을 커스터마이징할 때 쓸 수 있는 CSS 변수를 제공해요. 자세한 내용은 ConfigProvider 컴포넌트 문서를 참고하세요.
| Name | Default Value |
|---|---|
| --nut-addresslist-bg | #fff |
| --nut-addresslist-border | #f0f0f0 |
| --nut-addresslist-font-color | #333333 |
| --nut-addresslist-font-size | 16px |
| --nut-addresslist-mask-bg | rgba(0, 0, 0, 0.4) |
| --nut-addresslist-addr-font-color | #666666 |
| --nut-addresslist-addr-font-size | 12px |
| --nut-addresslist-set-bg | #f5a623 |
| --nut-addresslist-del-bg | #e1251b |
| --nut-addresslist-contnts-contact-default | var(--nut-primary-color) |
| --nut-addresslist-contnts-contact-color | var(--nut-white) |
더 알아보기 (Learn more)
이 문서는 NutUI v4 공식 영문 문서를 한국어로 옮긴 글이에요. 최신 API와 변경 사항은 원문에서 확인하는 게 가장 정확해요.
- 원문 문서: AddressList · doc.en-US.md
- NutUI 공식 문서: nutui.jd.com / GitHub 저장소: jd-opensource/nutui