完成固定footer佈局後,我想要在footer中添加幾個按鈕,來控制中間部分顯示的頁面,相似微信。所以我須要實現一個tab切換的功能,我這裏用到了Weex提供的<slider>
組件。vue
<template> <div class="wrapper"> <slider class="tab-container" auto-play="false" v-bind:index="sel" v-on:change="slideChange"> <div class="tab tab1"> <text>sel={{sel}}</text> </div> <div class="tab tab2"><text>sel={{sel}}</text></div> <div class="tab tab3"><text>sel={{sel}}</text></div> </slider> <div class="footer"> <a class="button" v-on:click="sel=0"><text>t1</text></a> <a class="button" v-on:click="sel=1"><text>t2</text></a> <a class="button" v-on:click="sel=2"><text>t3</text></a> </div> </div> </template> <script> import Files from "@/components/Files"; export default { name: "App", components: { Files }, data() { return { sel: 0 }; }, methods: { slideChange: function(nindex) { // console.log(nindex) this.sel = nindex.index } } } </script> <style scoped> .wrapper { /* justify-content: center; */ background-color: azure; flex-direction: column; width: 750px; /* align-items: center; */ } .tab-container { background-color: beige; width: 750px; flex: 1; } .slide { width: 750px; } .tab { width: 750px; flex: 1; } .tab1 { background-color: darkcyan; } .tab2 { background-color: darkgoldenrod; } .tab3 { background-color: darkgreen; } .footer { background-color: rgba(255, 255, 0, 1); width: 750px; height: 100px; flex: 0; border-radius: 10px 10px 0 0; padding: 5px 5px 5px 5px; flex-direction: row; } .button { border-width: 2px; width: 250px; } </style>
最終實現效果包括經過左右滑動切換tab頁,也能夠經過下方按鈕點擊來切換tab頁面。微信
實現tab頁切換,一開始個人思路是多個div包含頁面,隱藏不須要顯示的div。並經過一個參數來選擇須要顯示的div。CSDN的一篇文章總結了經常使用的隱藏方式,其中我嘗試過前面三種,均無效。app
display:flex
是默認值,沒法修改。所以不能使用display:none
的方式隱藏元素。overflow:hidden
。但一個問題是它貌似對vue的class綁定支持有問題。<div v-bind:class="hide: sel !=2" class="tab tab2"><text>sel={{sel}}</text></div>
來選擇時,能夠在調試器中看到div
包含了hide
類,可是hide
類中的overflow:hidden
樣式並未生效(firefox調試器中沒法看到該樣式)。使用長寬設爲0的方案存在一樣的問題。暫未在文檔中找到相關狀況的說明。<slider>
的change
事件,文檔中寫包含index參數的意思是它的參數是一個object,index是這個object的一個對象。而不是以index做爲函數參數。