A. The parent method showMessage is called with 'Hello!' as argument.
B. Nothing happens because the event name is incorrect.
C. An error occurs because $emit cannot send strings.
D. The child component updates its own data with 'Hello!'.
Solution
Step 1: Understand event emission and listening
The child emits an event named 'alert' with the string 'Hello!'. The parent listens for 'alert' and calls showMessage.
Step 2: Trace the event flow
When sendAlert() runs, the parent receives the event and calls showMessage('Hello!').
Final Answer:
The parent method showMessage is called with 'Hello!' as argument. -> Option A
Quick Check:
Child emits event, parent listens and reacts [OK]
Hint: Child emits event, parent listens with @event [OK]
Common Mistakes:
Thinking event names must be different in child and parent
Believing $emit cannot send string data
Assuming child updates itself on emit
4. Identify the error in this Vue child component method:
methods: {
notify() {
$emit('notify')
}
}
medium
A. Event name 'notify' is reserved and cannot be used.
B. Missing this before $emit causes a ReferenceError.
C. The method should return a value after emitting.
D. The methods object cannot contain functions.
Solution
Step 1: Check method syntax for emitting events
In Vue, $emit must be called with this context inside methods.
Step 2: Identify the missing this
The code calls $emit('notify') without this, causing a ReferenceError.
Final Answer:
Missing this before $emit causes a ReferenceError. -> Option B
Quick Check:
Always use this.$emit inside methods [OK]
Hint: Use this.$emit, not just $emit inside methods [OK]
Common Mistakes:
Omitting this before $emit
Thinking event names are restricted
Expecting methods to return values after emit
5. You want a child component to emit an event change only when a new value is different from the old one. Which code correctly implements this logic inside the child?
The event should emit only if the new value differs from the current this.value.
Step 2: Check each option's logic
The code that uses if (newVal !== this.value) { this.$emit('change', newVal) } correctly emits only on change. Code that emits unconditionally sends every time. Code using if (newVal == this.value) emits when values match (wrong logic). Code with this.emit uses invalid syntax.
Final Answer:
methods: {
updateValue(newVal) {
if (newVal !== this.value) {
this.$emit('change', newVal)
}
}
} -> Option C
Quick Check:
Emit only if newVal differs from current [OK]
Hint: Emit event only when new value differs [OK]
Common Mistakes:
Emitting event unconditionally
Using == instead of !== for change detection
Calling this.emit instead of this.$emit
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.