Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change event happens before v-model updates the value #1931

Closed
bhaidar opened this issue Aug 22, 2020 · 4 comments
Closed

change event happens before v-model updates the value #1931

bhaidar opened this issue Aug 22, 2020 · 4 comments
Labels
🐞 bug Something isn't working

Comments

@bhaidar
Copy link

bhaidar commented Aug 22, 2020

Version

3.0.0-rc.7

Reproduction link

https://codesandbox.io/s/suspense-vue3-4vgle

Steps to reproduce

  1. Select a country from the dropdown list
  2. No data for the selected country is shown
  3. Select another country
  4. The data for the first country selected is now shown

What is expected?

The first time the country is selected to show data for that country right away

What is actually happening?

  1. The first time I select a country, the selectedCountry ref variable is showing as an object with the property value set to the country selected.
  2. When the code tries to access selectedCountry.value it returns null. Although when I debug in the DevTools, the selectedCountry is a valid object with the value property set to the country selected.

I expect the v-model on the select to automatically bind to the selectedCountry the first time I select a value.

@skirtles-code
Copy link
Contributor

<select id="country" v-model="selectedCountry" @change="fetchData">

I believe the problem is that the change listener is being called before v-model updates selectedCountry.

@posva posva changed the title ref object has value, but when ".value" is accessed gives null first time change event happens before v-model updates the value Aug 22, 2020
@posva posva added the 🐞 bug Something isn't working label Aug 22, 2020
@posva
Copy link
Member

posva commented Aug 22, 2020

Marked as a bug because it works on Vue 2

@peng
Copy link

peng commented Aug 24, 2020

@bhaidar Can you show a full example. I saw no select in your example code. Fetch data have cors problem. Use fake data replace

@skirtles-code
Copy link
Contributor

@peng It seems the CodeSandbox example has been changed since it was first posted.

Here's an example of the same problem:

https://jsfiddle.net/skirtle/24jk3roL/

@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants