|
@@ -2,7 +2,7 @@
|
|
<html lang="zh">
|
|
<html lang="zh">
|
|
|
|
|
|
<head>
|
|
<head>
|
|
- <title>计算属性</title>
|
|
|
|
|
|
+ <title></title>
|
|
<meta charset="UTF-8">
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<script src="https://unpkg.com/vue/dist/vue.js"></script>
|
|
<script src="https://unpkg.com/vue/dist/vue.js"></script>
|
|
@@ -10,7 +10,8 @@
|
|
|
|
|
|
<body>
|
|
<body>
|
|
<div id="myApp">
|
|
<div id="myApp">
|
|
- 今年3月3日发卖的任天堂新一代主机Switch的价格是:{{price}}円,含税价格为:{{priceInTax}}円,折合人民币为:{{priceChinaRMB}}元。
|
|
|
|
|
|
+ <p>今年3月3日发卖的任天堂新一代主机Switch的价格是:{{price}}円,含税价格为:{{priceInTax}}円,折合人民币为:{{priceChinaRMB}}元。</p>
|
|
|
|
+ <button @click="btnClick(10800)">把含税改价为10800円</button>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
<script>
|
|
var myApp = new Vue({
|
|
var myApp = new Vue({
|
|
@@ -19,13 +20,23 @@
|
|
price: 29980
|
|
price: 29980
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
- priceInTax: function(){
|
|
|
|
- return this.price * 1.08;
|
|
|
|
|
|
+ priceInTax: {
|
|
|
|
+ get:function(){
|
|
|
|
+ return this.price * 1.08;
|
|
|
|
+ },
|
|
|
|
+ set: function(value){
|
|
|
|
+ this.price = value / 1.08;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
priceChinaRMB: function(){
|
|
priceChinaRMB: function(){
|
|
return Math.round(this.priceInTax / 16.75);
|
|
return Math.round(this.priceInTax / 16.75);
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
+ methods: {
|
|
|
|
+ btnClick: function(newPrice){
|
|
|
|
+ this.priceInTax = newPrice;
|
|
|
|
+ },
|
|
|
|
+ },
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|
|
</body>
|
|
</body>
|