Skip to content

"mounted()" block "event" registration for "watch()" but not for "updated()" #4836

@ctf0

Description

@ctf0

#4827 as a refrence that some lifecycle hooks DO have the event available while not for others.

export default {
    props:['hasErrors'],
    components: {
        'FormErrors': require('./Errors.vue')
    },
    data() {
        return {
            input: ''
        }
    },
    mounted () { // get the hidden inputs value
        if (this.$el.type == 'hidden') {
            this.input = this.$el.value
        }
    },
    watch: { // send data to the central storage to be picked up by the parent
        input(val, oldVal) {
            storage.data.userInfo[event.target.name] = val;
        }
    },
}
  • error Cannot read property 'target' of undefined

without mounted()
https://cl.ly/3V3p3U2L2I3j/Screen%20Recording%202017-02-01%20at%2007.59%20PM.gif
with
https://cl.ly/3H3p3j3H3n2J/Screen%20Recording%202017-02-01%20at%2008.01%20PM.gif

fiddle
https://jsfiddle.net/svz0hb8j/2/

now if we replaced watch() with updated() the error is gone

updated() {
    storage.data.userInfo[event.target.name] = this.input;
},

don't know why this happens specially that both pretty much does the same thing. https://vuejs.org/v2/api/#updated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions