A little doubt about learning Vue.nextTick

var vm = new Vue({
    el: "-sharpexample",
    data: {
        message: "123"
    }
})

vm.message = "new message"

console.log(vm.$el.textContent)

Vue.nextTick(function () {

    console.log(vm.$el.textContent)

})

read some Vue.nextTick instructions on the Internet, saying that the operation will be carried out during the next task cycle (that is, after the DOM update is completed).

clipboard.png


vm.$el vmChrometextContent

:

clipboard.png

:

clipboard.png

Why is this?


when you use the chrome console to view, when you click on the properties, Chrome will query the properties of that value. If you don't believe it, you can turn JSON.stringify (vm) into a JSON string and see


console prints references, vm is always the same object, so you expand to see the same content. You can enter a breakpoint console.log (vm); debugger; in the first log statement to see the value printed by vm at this time.


because vm is an Object reference type data, vm only points to an address reference, and the actual data is stored in the heap.

if you click to view faster than the machine runs, then you can see the results you want to see.
in fact, when you click to view, the value has already changed according to the reference point

Menu