Vue选项卡

vue指令

  • v-model:双向绑定 在input、select、texteara、components中使用
  • v-cloak  防止页面出现闪烁的问题 只针对差值表达式
  • v-text  类似于差值表达式 单项绑定 不会解析html标签
  • v-html 会解析html标签后输出
  • v-pre 会跳过当前元素和其子元素的编译过程
  • v-once 执行一次性插值
  • v-on 绑定事件 缩写为 @click=“方法名” 或者 v-on:click="方法名"

事件修饰符

  • ent.pareventDefault() 或者 event.stopPropagation() 阻止默认行为、阻止事件冒泡
    //阻止单击事件继续执行
    <a v-on:click.stop="do"></a>
    
    //提交事件不刷新页面
    <form v-on:submit.prevent="onSubmit"></form>
    
    //阻止事件冒泡
    <a v-on:click.stop.prevent="do"></a>
    
    //处理自身函数
    <div v-on:click.self="do"></div>

按键修饰符

  • <input v-on:keyup.enter = "submit">  
  • <input @keyup.enter = "submit">

自定义按键修饰符

Vue.config.keyCodes.自定义名 = 按键对应的ASCII

  •         v-bind:响应html属性
    • <img v-bind:src="imageSrc">
    • <img :src="imageSrc">
  • 绑定class
    • <ul v-bind:class="{textcolor:isColor}"></ul>
    • <ul v-bind:class="[classA,classB]"></ul>
  • 绑定style
    • <ul v-bind:style="{color:red,margin:0 auto}"></ul>
    • <ul v-bind:style="[styleObj1,styleObj2]"></ul>
  • v-if 
    • <span v-if="flag"></span>
  • v-else-if
    • <span v-else-if="flag!=false"></span>
  • v-else
    • <span v-else></span>
  • v-show 是否显示
    • <span v-show="参数"><span>
  • v-for 循环
    • <ul v-for="(item,index) in 数据源" v-bind:key="item.id">

选项卡

<div id="app">
    
        <ul class="title" >
            <li v-for="(item,index) in title" v-bind:key="item.id" v-bind:class="currentIndex==index?'current':''" v-text="item.row" @click="change(index)"></li>  
        </ul>
        <ul class="con">
          <li v-for="(item,index) in datas" v-bind:key="item.id" v-show="currentIndex==index" v-text="item.row"></li>
        </ul>

</div>
 new Vue({
        el:'#app',
       
        data:{
            currentIndex :0,
            title:[{
                id:1,
                row:1,
            },{
                id:2,
                row:2,
            },{
                id:3,
                row:3,
            },{
                id:4,
                row:4,
            }],
            datas:[{
                id:1,
                row:11111,
            },{
                id:2,
                row:22222,
            },{
                id:3,
                row:33333,
            },{
                id:4,
                row:44444,
            }],
        },
        methods:{
            change(index){
                console.log(index);
                this.currentIndex=index
            }
        }
    })

Vue选项卡切换图片可以通过定义一个currentIndex,通过和循环遍历中的index比较,从而去给对应的元素添加相应类名。这样就可以给对应的选项卡添加背景色,以及显示对应的图片。具体实现可以参考以下步骤: 1.Vue组件中定义一个currentIndex变量,用于记录当前选中的选项卡的索引。 2.选项卡的HTML代码中,使用v-for指令循环渲染选项卡的标题,并绑定点击事件,点击时将currentIndex设置为当前选项卡的索引。 3.选项卡内容的HTML代码中,使用v-show指令根据currentIndex的值来显示对应的选项卡内容。 4.选项卡标题的HTML代码中,使用v-bind:class指令根据currentIndex的值来动态绑定选项卡的样式,以显示当前选中的选项卡。 具体代码实现可以参考以下示例: ``` <template> <div class="tab"> <div class="nav"> <a href="javascript:;" :class="{ 'hover': currentIndex === 0 }" @click="currentIndex = 0">图片一</a> <a href="javascript:;" :class="{ 'hover': currentIndex === 1 }" @click="currentIndex = 1">图片二</a> <a href="javascript:;" :class="{ 'hover': currentIndex === 2 }" @click="currentIndex = 2">图片三</a> </div> <div class="nav_con"> <div v-show="currentIndex === 0"><img src="./图片/2.jpg" alt=""></div> <div v-show="currentIndex === 1"><img src="./图片/3.jpg" alt=""></div> <div v-show="currentIndex === 2"><img src="./图片/4.jpg" alt=""></div> </div> </div> </template> <script> export default { data() { return { currentIndex: 0 } } } </script> <style> .tab .nav a { display: inline-block; padding: 10px; margin-right: 10px; background-color: #eee; border-radius: 5px 5px 0 0; } .tab .nav a.hover { background-color: #fff; } .tab .nav_con div { display: none; } .tab .nav_con div img { width: 100%; } .tab .nav_con div:first-child { display: block; } </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值