计算属性

知识点

  • computed

computed

处理元数据,便于进行二次利用。(比如:消费税自动计算功能)

  1. <div id="myApp">
  2. 今年3月3日发卖的任天堂新一代主机Switch的价格是:{{price}}円,含税价格为:{{priceInTax}}円,折合人民币为:{{priceChinaRMB}}元。
  3. </div>
  4. <script>
  5. var myApp = new Vue({
  6. el: '#myApp',
  7. data: {
  8. price: 29980
  9. },
  10. computed: {
  11. priceInTax: function(){
  12. return this.price * 1.08;
  13. },
  14. priceChinaRMB: function(){
  15. return Math.round(this.priceInTax / 16.75);
  16. },
  17. },
  18. });
  19. </script>