[v6] do something on variable update


if I’ve a reactive variable, how can do event on update?

let userData = $store.getters.userData;

I would do action when userData is populated

Ideally, this must be done inside of the store actions where you update the state which updates the getters as well.

thanks for help
at the moment i’m using this method:

into view

$f7.on(‘myCustomEvent’, function (formData) {
$f7.form.fillFromData(’#upd_form’, formData);

and this into store action (after success update)

f7app.emit(‘myCustomEvent’, us_data);

but seems that anoter way could be this

let numCart = $store.getters.getCartNum;
numCart.onUpdated((val) => {

could be this a good solution too?

this can work, as this adds callback on getter update. But in this case you have to remove callback when component removed/destroyed to avoid memory leaks:

const myCallback = (val) => {...};

let numCart = $store.getters.getCartNum;

$onBeforeUnmount(() => {