react中城市选择器组件

2025-10-20 23:45:02

在react项目当中使用城市选择器,

import React from 'react'

import './index.less'

import { Picker } from 'antd-mobile';

// 城市选择器

class CitySelect extends React.Component{

static defaultProps = {

label: '',

name: '',

value: '',

readOnly: 0,

placeholder:''

}

componentWillMount(){

this.init()

}

init=()=>{

const { name = '', value = '', onInit } = this.props;

onInit && typeof onInit === 'function' && onInit(name, value.replace(/,/g, '/'));

}

handleChange=(e)=>{

const { name = '', onChange } = this.props;

onChange && typeof onChange === 'function' && onChange(name, e.join(",").replace(/,/g, '/'), );

}

render(){

const districtData = JSON.parse(JSON.stringify(require('./area.json')));

districtData.forEach(v=>{

v.value=v.label

v.children.forEach(a=>{