记录一次v-if画面元素不能切换显示

记录v-if 切换元素显示不显示
最开始flg可以切换true和false,但是页面元素不会消失。
原因:methods方法名写错了
学完ES6以后,方法名写成了changeisflg:() => {。。。。。。。}

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
</head>
<body>
   <div id="app">
       <h1 v-if="isflg">这是用v-if控制的元素</h1>
       <input type="button" value="isflg" @click="changeisflg">
       <input type="button" value="切换flag" @click="isflg = !isflg">
       <h1 style="background-color: rebeccapurple;" v-if="buttonid == 'el01'">这是一个h1</h1>
       <h2 style="background-color: yellowgreen;" v-else-if=" buttonid == 'el02'">这是一个h2</h2>
       <h3 style="background-color: burlywood;" v-else>这是一个h3</h3>
       <input type="button" value="el01" @click="changeid1">
       <input type="button" value="el02" @click="changeid2">
       <input type="button" value="el03" @click="changeid3">
   </div>
   <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
   <script>
       var app = new Vue({
           el: "#app",
           data: {
               msg: "hello momo",
               isflg: true,
               buttonid: "el00"
           },
           methods: {
               changeisflg(){
                   this.isflg = !this.isflg
               },
               changeid1(){
                   this.buttonid = "el01"
               },
               changeid2(){
                   this.buttonid = "el02"
               },
               changeid3(){
                   this.buttonid = "el03"
               }
           }
       })
   </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值