view-design / ViewUI

A high quality UI Toolkit built on Vue.js 2.0
https://www.iviewui.com/
Other
2.65k stars 797 forks source link

[Bug Report]select组件中单选模式情况下,赋值给v-model的时候,不触发on-change事件 #997

Open WangZhenHao opened 3 years ago

WangZhenHao commented 3 years ago

Environment

浏览器版本/ vue-2.6.5

Reproduction link

https://jsfiddle.net/w0afLenb/

Steps to reproduce

改变v-model的值的时候

What is expected?

触发on-change事件

What is actually happening?

没有触发on-change事件


目前可以重写一下Select组件的watch的values方法

ViewUI.Select.watch.values = function(now, before){
    const newValue = JSON.stringify(now);
    const oldValue = JSON.stringify(before);

    // 改变 labelInValue 的实现:直接在 emit 时改数据
    const vModelValue = this.publicValue;
    const shouldEmitInput = newValue !== oldValue && vModelValue !== this.value;

    if (shouldEmitInput) {
        let emitValue = this.publicValue;
        if (this.labelInValue) {
            if (this.multiple) {
                emitValue = this.values;
            } else {
                emitValue = this.values[0];
            }
        }
        this.$emit('input', vModelValue); // to update v-model
        this.$emit('on-change', emitValue);
        this.dispatch('FormItem', 'on-form-change', emitValue);
    } else if(!this.multiple) {
        const bNow = now[0] || {}
        const bValue = before[0] || {};
        if(bNow.value !== bValue.value) {
            this.$emit('on-change', this.publicValue);
        }

    }
 }