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))
})

Explanation

$onAction is also the basis for analytics or undo plugins. It returns a function to unsubscribe.

Further reading

Problem with a question

Vue · Middle · question 67

Test yourself

Take the Vue · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz