Property setter set computing

<!DOCTYPE html>
<html lang="zh">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <link href="../css/style.css" rel="stylesheet"> </head>

< Body > 
< div the above mentioned id = "myApp" > 
    < the p- > this year March 3rd sales of Nintendo's next-gen consoles Switch the price is: {{price}} yen, including tax price: {{priceInTax}} yen, RMB is: {{priceChinaRMB}} element. </ P > 
    < Button @click = "btnClick (10800)" > the price is 10800 yen tax change </ Button > 
</ div > 
< Script > 
    var myApp =  new new Vue ({
        on: ' #myApp ' ,
        data: {
            price: 29980
        },
        computed: {
            priceInTax: {
                get:function(){
                    return this.price * 1.08;
                },
                set: function(value){
                    this.price = value / 1.08;
                }
            },
            priceChinaRMB: function(){
                return Math.round(this.priceInTax / 16.75);
            },
        },
        methods: {
            btnClick: function(newPrice){
                this.priceInTax = newPrice;
            },
        },
    });
</script>
</body>

</html>

 

Guess you like

Origin www.cnblogs.com/Jeely/p/11057243.html
Recommended