Notas de estudio de Vue (16) - caso meteorológico

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>天气案例</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../js/vue.js"></script>
  
</head>
<body>
<!-- 准备一个容器 -->
<div id="root">
 <h2>今天天气很{
    
    {info}}</h2>
 <!-- 绑定事件的时候:@xxx:"yyy" yyy可以写一些简单的语句 -->
  <button @click="ishot=!ishot">切换天气</button>
 <button @click="changeweather">切换天气</button>
</div>
 
<script type="text/javascript">
Vue.config.productionTip=false


new Vue({
    el:'#root',
    data:{
        ishot:true
    },
    computed:{
        info(){
            return this.ishot?'hot':'cool'
        }
    },
    methods:{
        changeweather(){
            this.ishot=!this.ishot
        }
    }
})
 
</script>
</body>
</html>

Supongo que te gusta

Origin blog.csdn.net/weixin_54763080/article/details/128837718
Recomendado
Clasificación