diff --git a/app/components/WeatherSearchForm.tsx b/app/components/WeatherSearchForm.tsx index 04dff4f..ab0ac03 100644 --- a/app/components/WeatherSearchForm.tsx +++ b/app/components/WeatherSearchForm.tsx @@ -7,7 +7,7 @@ import { useWeatherStore } from '@/store/weatherStore'; export function WeatherSearchForm() { - const [isLoading, currentWeather, searchWeather, refreshWeather] = useWeatherStore(); + const {isLoading, currentWeather, searchWeather, refreshWeather} = useWeatherStore(); const [city, setCity] = useState(''); const [inputError, setInputError] = useState(''); @@ -25,11 +25,7 @@ export function WeatherSearchForm() { setInputError('请输入城市名称'); return; } - if (!trimmedCity) { - setInputError('请输入有效的城市名称'); - return; - } - + if (trimmedCity.length < 2) { setInputError('请输入至少2个字符'); return; @@ -40,10 +36,9 @@ export function WeatherSearchForm() { return; } await searchWeather(trimmedCity); - } - + return ( -