The usage of setTimeout in nextTick and JS in vue

problem description

in vue, I have the following templates:

<i class="bar" :style="style">
    <i class="dot"></i>
</i>

then the code in js is as follows:

props: {
        progress: {
            type: Number,
            default: function () {
                return 0;
            }
        },
        userInfo: {
            type: Object,
            default: function () {
                return {};
            }
        }
    },
    mounted() {
        let self = this;
        self.$nextTick(() => {
            self.width = self.progress;
        })
        // setTimeout(() => {
        //     this.width = this.progress;
        // })

    },
    computed: {
        style() {
            return {
                width: this.width + "%",
            }
        }
    },
The style of

bar has a dynamic effect of width change:

transition: width 0.5s ease;

Why do I have no dynamic effect when I use nextTick, but why do I have dynamic effect when I use setTimeout?

Jan.12,2022

is quite detailed


nextTick: delays the callback until after the next DOM update cycle
setTimeout: delays the callback to after the specified time
the prerequisites for both callbacks are different

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-1b388c3-344d1.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-1b388c3-344d1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?