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

[Bug Report]Cascader 组件on-change事件回调里面,v-mode的值,未及时更新 #375

Open
dingh123 opened this issue Jul 3, 2024 · 1 comment
Labels
Bug Something isn't working

Comments

@dingh123
Copy link

dingh123 commented Jul 3, 2024

Environment

windows 10 , Google Chrome 126.0.6478.127, 当前 Vue 版本为 3.2.36,View UI Plus 版本为 1.3.1

Reproduction link

https://run.iviewui.com/preview/Vl0VdZ59

Steps to reproduce

Cascader 组件on-change事件回调里面,v-mode的值,未及时更新

What is expected?

on-change后能直接v-model绑定的值及时更新

What is actually happening?

on-change后能直接v-model绑定的值还是上次的

@dosubot dosubot bot added the Bug Something isn't working label Jul 3, 2024
Copy link

dosubot bot commented Jul 3, 2024

@dingh123 Hello there! I'm here to help you with any bugs, questions, or contributions you might have. Let's work on resolving your issue together.

The issue with the Cascader component's on-change event callback not updating the v-model value in a timely manner is due to the emitValue method being called before the currentValue is updated in the handleSelectItem method. This causes a delay in the update of the v-model value.

To fix this, you should call emitValue after the currentValue has been updated. This can be achieved by using nextTick to ensure the DOM updates are completed before emitting the event:

methods: {
    handleSelectItem (index) {
        const item = this.querySelections[index];
        // other logic
        this.updatingValue = true;
        this.currentValue = newVal;
        nextTick(() => {
            this.emitValue(this.currentValue, oldVal);
        });
    }
}

This ensures that the currentValue is updated before the on-change event is emitted, thus updating the v-model value in a timely manner [1].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant