javascript - Vue newbie asking for help. v-for and v-if render multiple elements at the same level. How to change the display/hide of one of the elements individually?
淡淡烟草味
淡淡烟草味 2017-06-12 09:27:36
0
2
1050

I am practicing by making a todolist that can be added, deleted, and modified, imitating www.todolist.cn, and got stuck when re-editing the todo content. The official solution has not been summarized, so I am here to ask for help. the following.

Clicking on the text changes to input modification, but the effect is like this
Because my v-if is bound to the same variable, it will definitely be changed globally, but for vue My understanding is too shallow and I can’t think of effective methods.
Code: `

 NBtodoList   




`
Is there any way to hide only the current span and display the input after the revamp event is triggered? Ask the experts for advice!

淡淡烟草味
淡淡烟草味

reply all (2)
扔个三星炸死你
this.isRevamp = !this.isRevamp;

This method will show or hide all todos together,

To target only a certain todo, you can add an isRevamp to each todo, and then it becomes:

todo.isRevamp = !todo.isRevamp;

But this requires that every todo in your data contains isRevamp at the beginning. If you want to add it dynamically, it will be more troublesome. Please see the "Responsive Principle" section in the document: https://cn.vuejs. org/v2/guide...

But there is a simple way to deal with it: add an index variable to the data,
roughly like this:

  • {{v}}
  • show:function(i){ this.index=i; }
      小葫芦

      It’s very simple, just bind a state variable to each element.

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!