vue組件開發(fā)之tab切換組件使用詳解
本文實(shí)例為大家分享了vue組件開發(fā)之tab切換組件的具體使用代碼,供大家參考,具體內(nèi)容如下
代碼:
<template> <div class='tab-slider'> <div class='tab'> <span v-for='(item, index) in items' v-bind: @click='toggle(index)'>{{item.tab}}</span> </div> <div class='tab-content'> <div class='wrapbox clearboth'> <div v-for='(item, index) in items'>{{item.tabContent}}</div> </div> </div> </div></template><script> export default { name: ’tabSlider’, data (){ return { actived: 0, items: [{ ’tab’: ’tab1’, ’tabContent’: ’content1’ },{ ’tab’: ’tab2’, ’tabContent’: ’content2’ },{ ’tab’: ’tab3’, ’tabContent’: ’content3’ },{ ’tab’: ’tab4’, ’tabContent’: ’content4’ }] } }, methods: { //獲取圖片base64實(shí)現(xiàn)預(yù)覽 toggle(index){ this.actived = index; document.querySelector('.tab-content .wrapbox').style.webkitTransform = 'translateX(-' + (this.actived * 400) + 'px)'; } } }</script><style scoped> *{margin:0 auto;padding:0;font-family:'微軟雅黑';} .clearboth::after{ content:''; display:block; clear:both; } .tab-slider{ height:auto; width:400px; margin:50px auto; } .tab-slider .tab{ display:flex; height:40px; line-height:40px; background:#ccc; } .tab-slider .tab span{ display:block; width:100%; text-align:center; cursor:default; } .tab-slider .tab .active{ background:red; } .tab-slider .tab-content{ height:300px; width:400px; overflow:hidden; } .tab-slider .tab-content .item{ float:left; height:300px; width:400px; line-height:300px; text-align:center; font-size:60px; background:#eee; } .tab-slider .wrapbox{ width:2000px; transition: all 1s; }</style>
本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. asp讀取xml文件和記數(shù)2. XML入門的常見問(wèn)題(一)3. 讀寫xml文件的2個(gè)小函數(shù)4. 告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單5. 不同瀏覽器對(duì)XML的解析是不同的6. html小技巧之td,div標(biāo)簽里內(nèi)容不換行7. 阿里前端開發(fā)中的規(guī)范要求8. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案9. IE6/IE7/IE8/IE9中tbody的innerHTML不能賦值的完美解決方案10. webpack高級(jí)配置與優(yōu)化詳解
