5

My code like this :

updated() {
    console.log('test')
}, 

Demo and full code like this : https://jsfiddle.net/50wL7mdz/58492/

I check on console, the result of console.log('test') not display

If I use mounted, it works

Why if I use updated, it does not work?

How can I solve the problem?

1
  • I could be wrong but I'm pretty sure it's because it's on the root instance and not a component. What are you updating on the instance? Commented Sep 4, 2017 at 8:40

2 Answers 2

5

You are not actually updating anything, check out this JSFiddle:

https://jsfiddle.net/50wL7mdz/58496/

This data is your initial data so this will never trigger an update hook.

data: {
  message: 'Hello Vue.js!'
}

Once I change the initial data in the mounted lifecycle hook you see that the updated hook gets triggered.

Sign up to request clarification or add additional context in comments.

3 Comments

So do you mean there should be updated data? If there is no updated data then the updated does not work?
From the documentation: Updated: Called after a data change causes the virtual DOM to be re-rendered and patched. So you actually need to change the value of a data property. So yes, there should be updated data.
Okay. Thanks a lot
0

Another situation that can make updated() fail has to do with v-if. If the initial value of v-if for a component is true, the updated() function works. But updated() can fail if the initial value of v-if is false.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.