tab vue 竖排_vue 插件tab选项卡(转载)

{ { {item}}}

var VueTouch = require ('vue-touch');

Vue.use (VueTouch);

import requestAnimFrame from"utils/requestAnimFrame"const sign= (num)=>{return num >= 0 ? 1 : -1}

exportdefault{

props: ["options", "state"],

data(){return{

tabsWrapID: undefined,//外容器ID

wrapWidth: "", //外容器宽度

tWidth: 0, //每一个选项卡应该有多宽

width: 0, //宽度。

startTransX: 0,

transX:0, //元素样式偏移。

cssX: 0 //动作中css实际完成的偏移。

}

},

methods: {

init(){this.wrapWidth = document.getElementById (this.tabsWrapID).offsetWidth;this.tWidth = this.wrapWidth / this.options.count;this.width = this.tWidth * this.options.htmls.length;

setTimeout(function(){this.$el.style["height"]= this.$el.children[0].clientHeight+"px";

}.bind(this),0)if (this.options.pin) {var elemRect = this.$el.getBoundingClientRect ();var windowOffset = this.getWindowOffset ();var winOffsetY =windowOffset.offsetY;this.elemOffsetY = elemRect.top +winOffsetY;

document.addEventListener ('scroll', this.isTop);

}

},

onPan(event){if (this.options.disPan) return;this.transX = eve

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过以下步骤使用vue2脚手架实现tab选项: 1. 在父组件中定义一个数组tabs,包含选项的标题和内容: ```javascript data() { return { tabs: [ { title: '选项1', content: '内容1' }, { title: '选项2', content: '内容2' }, { title: '选项3', content: '内容3' } ], activeTab: 0 } } ``` 2. 在模板中使用v-for指令渲染选项的标题,并绑定click事件,将索引赋值给activeTab: ```html <template> <div> <div class="tabs"> <div v-for="(tab, index) in tabs" :key="index" :class="{ active: activeTab === index }" @click="activeTab = index">{{ tab.title }}</div> </div> <div class="tab-content">{{ tabs[activeTab].content }}</div> </div> </template> ``` 3. 根据activeTab的值显示对应选项的内容。可以使用计算属性实现: ```javascript computed: { activeContent() { return this.tabs[this.activeTab].content } } ``` 4. 根据需要自定义样式即可实现tab选项效果。 完整代码示例: ```html <template> <div> <div class="tabs"> <div v-for="(tab, index) in tabs" :key="index" :class="{ active: activeTab === index }" @click="activeTab = index">{{ tab.title }}</div> </div> <div class="tab-content">{{ activeContent }}</div> </div> </template> <script> export default { data() { return { tabs: [ { title: '选项1', content: '内容1' }, { title: '选项2', content: '内容2' }, { title: '选项3', content: '内容3' } ], activeTab: 0 } }, computed: { activeContent() { return this.tabs[this.activeTab].content } } } </script> <style> .tabs { display: flex; justify-content: space-between; border-bottom: 1px solid #ccc; margin-bottom: 10px; } .tabs div { padding: 10px; cursor: pointer; } .tabs div.active { border-bottom: 2px solid #333; } .tab-content { padding: 10px; } </style> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值