Skip to content

[vue3.x] Deep watching an array (modelValue) #683

@01vector

Description

@01vector

Describe the bug

(ru)
Добрый день!
У меня есть modelValue: number[] = [1960, 2023]. К этому массиву привязан vue-slider посредством v-model. В то же время, к каждому из элементов массива привязан инпут следующим образом: <AppInput v-for="(input, index) in inputs" v-model.number="modelValue[index]" />
Когда я перемещаю точку на vue-slider, изменения фиксируются и все работает как и должно. Когда я пытаюсь вводить значения в свой AppInput, vue-slider не видит изменений.
Это связано с тем, что watch для modelValue в компоненте vue-slider не использует параметр deep: true.
Подскажите, пожалуйста, есть ли способ обойти подобное поведение, не редактируя исходный код библиотеки?
Большое спасибо за ответ!

(en)
Hello!
I have a modelValue: number[] = [1960, 2023]. The vue-slider is bound to this array using v-model. At the same time, each element of the array is bound to an input using the following syntax: <AppInput v-for="(input, index) in inputs" v-model.number="modelValue[index]" />
When I move the slider handle, the changes are detected and everything works as expected. However, when I try to enter values in the AppInput, the vue-slider doesn't see the changes.
This is because the watch for modelValue in the vue-slider component does not use the deep: true option.
Please, let me know if there is a way to workaround this behavior without modifying the source code of the library.
Thank you very much for your response!

Environment

  • OS & Version: macOS
  • Vue version: 3.3.4
  • Component Version: [e.g. v4.0.0-beta.1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions