[Vuejs]-Variable undefined unless wrapped in setTimeout

0👍

Only your user is a computed property, and you are only calling to concatenate the user name and lastname in mounted. When mounted has been run, it is never called again. Therefore it works when you set a timeout, the user has then had time to be fetched from the store and can be displayed. You can use watch to listen to changes in the user and then set the value. As your form is an object, we need to listen deep and maybe you need to use immediate as well. So add a watcher:

watch: {
    user: {
        immediate:true,
        deep: true,
        handler(user) {
            this.$set(this.form, 'responsible_clerk', user.name + " " + user.lastname);
        }
    }
}

Leave a comment