index.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  8. <link href="../css/style.css" rel="stylesheet"> </head>
  9. <body>
  10. <div id="myApp">
  11. <p>今年3月3日发卖的任天堂新一代主机Switch的价格是:{{price}}円,含税价格为:{{priceInTax}}円,折合人民币为:{{priceChinaRMB}}元。</p>
  12. <button @click="btnClick(10800)">把含税改价为10800円</button>
  13. </div>
  14. <script>
  15. var myApp = new Vue({
  16. el: '#myApp',
  17. data: {
  18. price: 29980
  19. },
  20. computed: {
  21. priceInTax: {
  22. get:function(){
  23. return this.price * 1.08;
  24. },
  25. set: function(value){
  26. this.price = value / 1.08;
  27. }
  28. },
  29. priceChinaRMB: function(){
  30. return Math.round(this.priceInTax / 16.75);
  31. },
  32. },
  33. methods: {
  34. btnClick: function(newPrice){
  35. this.priceInTax = newPrice;
  36. },
  37. },
  38. });
  39. </script>
  40. </body>
  41. </html>