0
0
Vueframework~10 mins

onUpdated and onBeforeUpdate in Vue - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the lifecycle hook that runs before the component updates.

Vue
import { [1] } from 'vue';
Drag options to blanks, or click blank then click option'
AonMounted
BonBeforeUpdate
ConUpdated
DonCreated
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing onMounted because it runs only once after mounting.
Choosing onUpdated which runs after the update, not before.
2fill in blank
medium

Complete the code to import the lifecycle hook that runs after the component updates.

Vue
import { [1] } from 'vue';
Drag options to blanks, or click blank then click option'
AonUpdated
BonUnmounted
ConBeforeUpdate
DonMounted
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing onBeforeUpdate which runs before the update.
Choosing onMounted which runs only once after mounting.
3fill in blank
hard

Fix the error in the code by choosing the correct lifecycle hook to run code before the DOM updates.

Vue
export default {
  setup() {
    [1](() => {
      console.log('DOM will update soon');
    });
  }
}
Drag options to blanks, or click blank then click option'
AonUpdated
BonMounted
ConUnmounted
DonBeforeUpdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using onUpdated which runs after the DOM updates.
Using onMounted which runs only once after mounting.
4fill in blank
hard

Fill both blanks to correctly use the hooks that run before and after the component updates.

Vue
import { [1], [2] } from 'vue';

export default {
  setup() {
    [1](() => {
      console.log('Before update');
    });
    [2](() => {
      console.log('After update');
    });
  }
}
Drag options to blanks, or click blank then click option'
AonBeforeUpdate
BonMounted
ConUpdated
DonUnmounted
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the hooks' order.
Using onMounted or onUnmounted instead.
5fill in blank
hard

Fill all three blanks to create a Vue component that logs messages before update, after update, and when mounted.

Vue
import { [1], [2], [3] } from 'vue';

export default {
  setup() {
    [1](() => {
      console.log('Component mounted');
    });
    [2](() => {
      console.log('Before update');
    });
    [3](() => {
      console.log('After update');
    });
  }
}
Drag options to blanks, or click blank then click option'
AonMounted
BonBeforeUpdate
ConUpdated
DonUnmounted
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of hooks.
Using onUnmounted instead of onMounted.