1. <div id="app">
    2. <!-- 三元表达式 -->
    3. <p> 今天天气很 {{ weather ? '炎热' : '寒冷' }}</p>
    4. <button type="button" @click="changestatus()">点我</button>
    5. </div>
    6. <script >
    7. var vm = new Vue ({
    8. data : {
    9. weather: true,
    10. },
    11. methods:{
    12. changestatus(){
    13. this.weather = ! this.weather
    14. }
    15. }
    16. });
    17. vm.$mount("#app")
    18. </script>

    其实我们并不需要在模版中使用复杂的逻辑,例如三元表达式
    我们应该使用 methods 和 computed属性

    <body>
            <script type="text/javascript" src="https://unpkg.com/vue/dist/vue.js"></script>
            <div id="app">
                <!-- 三元表达式 -->
                <p> 今天天气很 {{ info }}</p>
                <button type="button" @click="changestatus()">点我</button>
            </div>
    
            <script >
                var vm = new Vue ({
                    data : {
                        weather: true,
                    },
                    methods:{
                        changestatus(){
                            this.weather = ! this.weather
                        }    
                    },
                    computed: {
                        info(){
                             return this.weather ? '炎热' : '寒冷' 
                        }
                    }
                });
                vm.$mount("#app")
            </script>    
        </body>