Vue · Middle · Question 67 of 75
How do you log every action of a Pinia store and its errors?
store.$onAction(({ name, after, onError }) => {
after(() => log(name, 'ok'))
onError((e) => log(name, e))
})- ✓Correct answer: Subscribe with
$onActionand use theafter/onErrorhooks - 2Wrap every action in
try/catchmanually only - 3Pinia doesn't expose action events
Explanation
$onAction is also the basis for analytics or undo plugins. It returns a function to unsubscribe.