Vue with Value object

by ktsn

HTML

<div id="app">
  {{ price.format() }}
</div>

TypeScript

class Price {
  constructor(private value: number) {
    Object.seal(this);
  }
  
  format() {
    return `¥${this.value}`;
  }
}

const app = new Vue({
	el: '#app',
  data: {
    price: new Price(100)
  }
});

console.log(app.price);

setTimeout(() => {
	app.price = new Price(200);
	console.log(app.price);
}, 1000);