[Vuejs]-This is a question when using openweather API with axios

1๐Ÿ‘

Every time you hit enter, it submits the form. The default behavior for form submission reloads the component, which then by default returns โ€˜seoulโ€™ for city.

Try binding an event listener to the formโ€™s submission, and comment out the method call on update(). This will prevent excessive API calls.

<form @submit.prevent="weatherData">
      <h3><span> ๋„์‹œ</span>๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”</h3>
      <input type="text" v-model="city" />
      <button>ํ™•์ธ</button>
    </form>

Conversely, if you want the method to fire on input event, you should validate the input value before sending the API call, as some of the shorter entries throw a 404.

๐Ÿ‘คtris

Leave a comment