我使用的是https://www.npmjs.com/package/material-ui-phone-number包,它是从react-phone-input包中开发的,希望获得从下拉菜单中选择的旗帜上的国家代码基础。这有可能吗?我确实看到了对象' country‘的详细信息,但我无法获得国家代码。
<MuiPhoneNumber value={phone || ''} defaultCountry={'us'} preferredCountries={['gb', 'us']} disableAreaCodes={true} value={phone || ''} onChange={handleOnChange} />我只能在onChange中获得目标值
发布于 2021-07-08 02:17:49
正如您在material-ui-phone-number中的supported events中看到的那样
<MuiPhoneNumber onChange={(value, country) => console.log(country)} />第二个参数将为您提供一个国家数据对象,其中包括:name,dialCode,country code。
也是
未从onKeyDown event返回
国家/地区数据对象
发布于 2021-03-03 04:42:09
我自己也遇到了这个问题,弄清楚了……
{<MuiPhoneNumber value={phone || ''} defaultCountry={'us'} preferredCountries={['gb', 'us']} disableAreaCodes={true} value={phone || ''} onChange={(country) => handleOnChange(country.countryCode)} />}只需将country传递给onchange并使用country.countryCode获取代码,或者使用country.name获取名称,使用country.dialCode获取拨号代码。
干杯
https://stackoverflow.com/questions/59461383
复制相似问题