Why v-model doesn't work with an array and v-for loop?

前端 未结 2 958
南方客
南方客 2021-02-14 12:05

I got a custom select component, it works with a simple variable, but when used with v-for it won\'t work:

https://jsfiddle.net/7gjkbhy3/19/



        
2条回答
  •  梦毁少年i
    2021-02-14 12:14

    I don't like the idea of having to change the view model to resolve a framework design constraint. What if the model is to be sent to your backend via an API call? It would involve an additional step of having to mutate the model.

    My solution to this was to create a Vue component that boxes the value at each array index into an object that can be referenced within it's slot. It then reacts to the data-changing by updating the array at the specified index via a watcher.

    boxed-value.vue

    
    
    
    

    Example

提交回复
热议问题