您当前的位置: 首页 >  vue.js

dawn

暂无认证

  • 6浏览

    0关注

    204博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Vue.js(7):v-if、v-else-if、v-else、v-show、v-for

dawn 发布时间:2021-10-31 16:55:10 ,浏览量:6

  v-if和v-show功能差不多,区别在于v-if如果不显示就注释掉了,而v-show则是通过style="display: none;"来隐藏的,另外v-show不支持v-else和。 




    
    
    
    Vue.js-V-if、V-show、v-for
    
    
        [v-cloak]{
            display: none;
        }
    


    
----------------V-if和V-show 显示与隐藏
{{info}} -- v-if
{{info}} -- v-show
{{ isDisplayed?'点击隐藏':'点击显示' }} ----------------V-if v-else-if v-else
输入字符A看到
输入字符B看到
输入字符C看到
以上条件都不满足显示
 你的输入值:{{sTemp}} ----------------V-for显示数组数据 (注意:要习惯性地加上:key,唯一值)
  • {{item.id}}--{{item.Name}}--{{item.ChineseScore}}-{{item.MathScore}}
----------------V-for显示对象数据
  • {{key}}--{{val}}--{{i}}
----------------V-for显示列表数字
  • {{i}}--{{count}}
//数据 var VueDataObj={ info:'Vus.js', sTemp:'B', isDisplayed:true, studentList:[ {Id:101,Name:'小明',ChineseScore:81.5,MathScore:87}, {Id:102,Name:'小宋',ChineseScore:61,MathScore:47.5}, {Id:103,Name:'小丽',ChineseScore:89.5,MathScore:83}, ], loginUser:{Id:1,name:'陆军',type:'操作员'}, }; //方法 var methods={ changeDisplayStatus(){ this.isDisplayed=!this.isDisplayed; }, valueChange(e){ console.log(this.iTemp); console.log(e.target.value); }, }; //计算属性 var computed={}; //监听 var watch={}; //Vue应用对象 var vm=new Vue({ el:'#demo', data:VueDataObj, methods, computed, watch, })

  显示图:

 

关注
打赏
1664252102
查看更多评论
立即登录/注册

微信扫码登录

0.1623s