Vue: dispatchEvent breaking model synchronization

Created on 7 Sep 2016  路  2Comments  路  Source: vuejs/vue

Hello, found this when I was trying to write unit tests for my module:

https://jsfiddle.net/iFarmGolems/cxc8cp34/

Why is this happening?

Most helpful comment

This happens because the change event fires before the DOM gets a chance to update. Therefore, the v-model updates the value on that change event to what it was before the DOM gets a chance to update.

The solution is a nextTick.

Here's an updated fiddle that works: https://jsfiddle.net/crswll/cxc8cp34/4/

All 2 comments

in 2.0 works fine

This happens because the change event fires before the DOM gets a chance to update. Therefore, the v-model updates the value on that change event to what it was before the DOM gets a chance to update.

The solution is a nextTick.

Here's an updated fiddle that works: https://jsfiddle.net/crswll/cxc8cp34/4/

Was this page helpful?
0 / 5 - 0 ratings