Recap
Long time no write Vue, and slightly strange, this thing is much more useful.
Afternoon saw a demand, select the album chart picture shows a carousel. Interface return to the album list, the user choose it over and then throw it back.
Until I saw e.target.className
I know that this matter is not simple. .
Vue is a data-driven
The data driver this is what I feel and jQuery
not the same place. jQuery
A tap, add class
, move more class
. Vue
What is the point, data logging, and then automatically notify view.
One is saved in the selected state DOM
, the selected one is stored in the js数据模型
inside.
So to see the use Vue
then get DOM
changed class
behavior, I stopped him in time. Saying you volunteer your time to Vue
doing. . .
Data-driven ideas together before and what will happen?
It is a data-driven view of data to process, if you only change the view does not change the data. He then refresh it in other places, it may lead to the view of sync. For example, when writing to write, then it is possible to read when reading out is not the same, why is this so? Because there are two places you can change it, Vue the DOM deleted, do not you write a new rendering of the state, when read read ghost. Think about this a luck thing, you can Haoshi it?
Vue how to achieve this effect
Said so much nonsense, first on the address bar, Portal - DEMO I wrote
the following simple talk about three kinds of writing ideas
- Id made of a selected array, and more to maintain a queue.
:class="{selected: ~checkSelect(item.id)}"
Rendering time to determine that there are an array of id no. - Id made of a selected target, to maintain a multi-object.
:class="{selected: selectList[item.id]}"
And compared to the previous object, then,id
as akey
look up a lot of convenience. Here we must note that.$set
, draw the focus to the exam. - Directly change the original object, one more parameter. This not very recommended.
When I finished writing the code, writing articles, the demand had changed. Uncomfortable. . . . To change the code. . . .
When I finished writing the code, writing articles, the demand had changed. Uncomfortable. . . . To change the code. . . .
When I finished writing the code, writing articles, the demand had changed. Uncomfortable. . . . To change the code. . . .