Skip to content

AddressEdit - Vant 4

AddressEdit

📍 Streamline address management with smart, user-friendly forms!

Intro

AddressEdit is your complete solution for managing shipping and billing addresses! This intelligent component makes it effortless for users to add, edit, and organize their addresses with features like area selection, address search, and smart validation. Perfect for e-commerce apps, delivery services, or any application that needs reliable address management! 🏠✨

Install

Ready to revolutionize how your users manage addresses? Let's get AddressEdit up and running! Register it globally with app.use() and you'll have a powerful address management system at your fingertips. Check out our Component Registration guide for more setup options! 🚀

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

Usage

Basic Usage - Smart Address Forms Made Simple! 🎯

Create a comprehensive address editing experience with just a few lines of code! This example shows how to build a complete address form with area selection, search functionality, and smart validation. Watch how easy it is to give users a delightful address management experience!

html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const searchResult = ref([]); constonSave = () => showToast('save'); constonDelete = () => showToast('delete'); constonChangeDetail = (val) => { if (val) { searchResult.value = [ { name: 'Name1', address: 'Address', }, ]; } else { searchResult.value = []; } }; return { onSave, onDelete, areaList, searchResult, onChangeDetail, }; }, };

API

Props

AttributeDescriptionTypeDefault
area-listArea Listobject-
area-columns-placeholderplaceholder of area columnsstring[][]
area-placeholderplaceholder of area input fieldstringArea
address-infoAddress InfoAddressEditInfo{}
search-resultAddress search resultAddressEditSearchItem[][]
show-deleteWhether to show delete buttonbooleanfalse
show-set-defaultWhether to show default address switchbooleanfalse
show-search-resultWhether to show address search resultbooleanfalse
show-areaWhether to show area cellbooleantrue
show-detailWhether to show detail fieldbooleantrue
disable-areaWhether to disable area selectbooleanfalse
save-button-textSave button textstringSave
delete-button-textDelete button textstringDelete
detail-rowsDetail input rows*numberstring*
detail-maxlengthDetail maxlength*numberstring*
is-savingWhether to show save button loading statusbooleanfalse
is-deletingWhether to show delete button loading statusbooleanfalse
tel-validatorThe method to validate tel(val: string) => boolean-
tel-maxlengthTel maxlength*numberstring*
validatorCustom validator(key: string, val: string) => string-

Events

EventDescriptionArguments
saveEmitted when the save button is clickedinfo: AddressEditInfo
focusEmitted when field is focusedkey: string
change v4.7.0Emitted when only the name and tel field are changed{key: string, value: string}
deleteEmitted when confirming deleteinfo: AddressEditInfo
select-searchEmitted when a search result is selectedvalue: string
click-areaEmitted when the area field is clicked-
change-areaEmitted when area changedselectedOptions: PickerOption[]
change-detailEmitted when address detail changedvalue: string
change-defaultEmitted when switching default addresschecked: boolean

Slots

NameDescription
defaultCustom content below address detail

Methods

Use ref to get AddressEdit instance and call instance methods.

NameDescriptionAttributeReturn value
setAddressDetailSet address detailaddressDetail: string-
setAreaCodeSet area codecode: string-

Types

The component exports the following type definitions:

ts
importtype { AddressEditInfo, AddressEditProps, AddressEditInstance, AddressEditSearchItem, } from'vant';

AddressEditInstance is the type of component instance:

ts
import { ref } from'vue'; importtype { AddressEditInstance } from'vant'; const addressEditRef = ref<AddressEditInstance>(); addressEditRef.value?.setAddressDetail('');

AddressEditInfo Data Structure

keyDescriptionType
nameNamestring
telPhonestring
provinceProvincestring
cityCitystring
countyCountystring
addressDetailDetailed Addressstring
areaCodeArea codestring
isDefaultIs default addressboolean

AddressEditSearchItem Data Structure

keyDescriptionType
nameNamestring
addressAddressstring

Area Data Structure

Please refer to Area component.

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-address-edit-paddingvar(--van-padding-sm)-
--van-address-edit-buttons-paddingvar(--van-padding-xl) var(--van-padding-base)-
--van-address-edit-button-margin-bottomvar(--van-padding-sm)-
--van-address-edit-button-font-sizevar(--van-font-size-lg)-

Explore more components and features to enhance your mobile app experience:

  • AddressList - Learn about address list components for managing multiple addresses
  • Area - Master area selection components for location picking
  • Field - Discover form field components for user input
  • Button - Understand button components and interactions
  • Form - Explore form validation and management
  • Picker - Learn about picker components for selections
  • ConfigProvider - Customize themes and global configurations
  • Advanced Usage - Component registration and advanced techniques
  • Vant 4 Overview - Explore all Vant 4 features and components

Enterprise-level mobile solution based on Vant