验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

vue如何使用动态组件实现TAB切换效果

阅读:1139 来源:乙速云 作者:代码code

vue如何使用动态组件实现TAB切换效果

一、方法1:使用Vant组件库的tab组件

Vant 2 - Mobile UI Components built on Vue

vue如何使用动态组件实现TAB切换效果

二、 方法2:手动创建tab切换效果

vue如何使用动态组件实现TAB切换效果

vue如何使用动态组件实现TAB切换效果

1.在components文件夹下创建切换的.vue页面、引入使用

import one from "./components/one";
import two from "./components/two";
import three from "./components/three";
import four from "./components/four";
components: {
    one,
    two,
    three,
    four,
},

2.布局:上面放tab点击的标签,下面放组件呈现对应内容

// 然后使用v-for循环出来呈现

3.写好上面的tab点击标签,定义数据修改样式

// 首先我们在data中定义数组cardArr存放点击tab的数据
data() {
   return {
      whichIndex: 0,
      cardArr: [
        {
          componentName: "动态组件一",
          componentId: "one",
        },{
          componentName: "动态组件二",
          componentId: "two",
        },{
          componentName: "动态组件三",
          componentId: "three",
        },{
          componentName: "动态组件四",
          componentId: "four",
        },
      ],
    };
},
// 又因为需要有高亮状态样式:默认索引0高亮
.highLight {
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
  transform: translate3d(0, -1px, 0);
}

三、完整代码




#app {
  width: 100%;
  height: 100vh;
  box-sizing: border-box;
  padding: 50px;
  .top {
    width: 100%;
    height: 80px;
    display: flex;
    justify-content: space-around;
    .crad {
      width: 20%;
      height: 80px;
      line-height: 80px;
      text-align: center;
      background-color: #fff;
      border: 1px solid #e9e9e9;
    }
    .highLight {
      box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
      transform: translate3d(0, -1px, 0);
    }
  }
  .bottom {
    margin-top: 20px;
    width: 100%;
    height: calc(100% - 100px);
    border: 3px solid pink;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>