template:
<div>
<label class="label">balance</label>
<h3 class="title is-4">${{ lobby.balance }}</h3>
</div>
code:
setup() {
const state = reactive({
lobby: {},
});
state.lobby = new Lobby(); //settimeout change balance in constructor is not re-render
setTimeout(() => {
state.lobby.balance = 123; // re-render is work
}, 1000);
return {
...toRefs(state),
};
}
Why isn't the balance change in the Lobby constructor reactive?
This would happen when
Lobby()'sbalanceproperty is not declared as aref:The solution would be to declare
balanceas aref:demo