javascript - The dynamic v-bind:class that adds attributes through control in the rendering list li of vue2.0 does not take effect immediately
给我你的怀抱
给我你的怀抱 2017-05-19 10:13:11
0
2
601

For example code:
The first step: Get a data object array from the server: [obj, obj, obj],
The second step: Add a browser object obj to each sub-object:

for(let i = 0; i

Step 3: Bind this attribute to the html structure to control the dynamic class

html: 
  • qwer
js: methods: { changeBg(item){ item.myObj = true } } css: .change_bg background: red

The result is: the myobj attribute has been changed to true each time it is clicked, but the dynamic class will not take effect until ul is refreshed (when refreshed, the ul data will not be reacquired).

给我你的怀抱
给我你的怀抱

reply all (2)
我想大声告诉你
array[i].myObj = false 改为 this.array.$set(i, {myObj: false})
    Ty80

    Correct answer upstairs. Because the attribute is added dynamically, you need to use the set method provided by vue to make the attribute an ES5 accessor attribute to track changes.

      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!