On the execution order of flushSchedulerQueue and nextTick in Vue Source Code

first take a look at the code example:

<template>
  <div ref="box">{{content}}</div>
</template>

<script>
export default {
  data() {
    return {
      content: "before"
    }
  },
  mounted() {
    this.nextTick(() => {
      console.log(this.$refs.box.innerHTML) // after
    })
    this.content = "after"
    this.nextTick(() => {
      console.log(this.$refs.box.innerHTML) // after
    })
  }
}
</script>

I have looked at the source code of Vue again these two days. NextTick (cb) will put cb push into callbacks, and this.content = "after" will also flushSchedulerQueue push the execution function of watcher dependent on content to callbacks, and then flushCallbacks after the synchronization code has been executed. In that case, when the first console.log (this.$refs.box.innerHTML) in the example is executed, the content is not updated, so why output after?

< hr >

to update, if I introduce Vue through the script tag, the output is before and after, but if it is run through a webpack build, the output is after.

Jul.11,2022

your first is after ?
https://jsfiddle.net/63180768...


I also encountered the same problem as the landlord. The local webpack packaged dev server,vue version 2.6.11.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ba0d97-44574.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ba0d97-44574.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?