Commit 38b23927 authored by 王玉鑫's avatar 王玉鑫

feat: 省市区hook

parent d110ff6a
import cityData from '@/utils/cities.json';
import { computed, ref } from 'vue';
export interface CityData {
value: string;
name: string;
parent?: string;
children?: CityData[];
}
/**
* 省市区数据
*/
export function useAddress() {
const cityList: CityData[] = cityData;
const currentProvince = ref<CityData | null>(null);
const currentCity = ref<CityData | null>(null);
const currentRegion = ref<CityData | null>(null);
/**
* 当前省的市列表
*/
const currentCityList = computed(() => {
return currentProvince.value?.children || [];
});
/**
* 当前市的区列表
*/
const currentRegionList = computed(() => {
return currentCity.value?.children || [];
});
return {
cityList,
currentProvince,
currentCity,
currentRegion,
currentCityList,
currentRegionList,
};
}
This diff is collapsed.
{ {
"extends": "@vue/tsconfig/tsconfig.dom.json", "extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "src/**/*.json"],
"exclude": ["src/**/__tests__/*"], "exclude": ["src/**/__tests__/*"],
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment