vue 相邻div的选项卡

终于找到了不是父子div做选项卡的方法了!!!

html
    <div id="mybox">
      <ul class="up">
        <li v-for="(item,index) in items"
          @mouseenter="tab(index,item.view)">
          {{item.type}}
        </li>
      </ul>
      <div class="down">
        <component :is="currentView"></component>
      </div>
    </div>
js
Vue.component('child1', {
      template: "<p>this is child1</p>"
    })
    Vue.component('child2', {
      template: "<p>this is child2</p>"
    })
    Vue.component('child3',{
      template:"<p>this is child 33</p>"
    })

    new Vue({
      el: '#mybox',
      data: {
        curId: 0,
        currentView: 'child1',
        items:[
          {type:'A',view:'child1'},
          {type:'B',view:'child2'},
          {type:'C',view:'child3'},
          {type:'D',view:'child4'},
        ],
      },
      methods:{
        tab(index,view){
          this.curId = index;
          this.currentView = view
        }
      }
    })

如果是用vue-cli
可以抽出为一个vue文件
例如home.vue中有一个选项卡,其中三个选项,内容很复杂
//home.vue

import child1 from './child1.vue'
import child2 from './child2.vue'
import child3 from './child3.vue'

export default{
    //其他省略
    components:{
    child1,
    child2,
    child3,
  },
}

//child1.vue

<template>
<div>
    <h1>hellohellohey</h1>
    <h2>请给我舞台</h2>
</div>
</template>

转载于:https://www.cnblogs.com/wulzt/p/9457709.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值