uni-app寫表格時列數過長時實現左右滑動效果


使用標簽包裹

                                        //使用scroll-view標簽包裹,設置左右可滑動,寬度100%,超出隱藏
                                        <scroll-view scroll-x="true" @scroll="scroll" style="width: 100%;overflow: hidden;white-space: nowrap;">
						<view class="scroll-view_H"> 
							<t-table @change="change">
								<t-tr>
									<t-th>序號</t-th>
									<t-th>姓名</t-th>
									<t-th>年齡</t-th>
									<t-th>愛好</t-th>
									<t-th>愛好1</t-th>
									<t-th>愛好2</t-th>
									<t-th>愛好3</t-th>
									<t-th>愛好4</t-th>
									<t-th>愛好5</t-th>
									<t-th>愛好1</t-th>
									<t-th>愛好2</t-th>
									<t-th>愛好3</t-th>
									<t-th>愛好4</t-th>
									<t-th>愛好5</t-th>
								</t-tr>
								<t-tr v-for="item in tableList" :key="item.id">
									<t-td>{{ item.id + 1 }}</t-td>
									<t-td>{{ item.name }}</t-td>
									<t-td>{{ item.age }}</t-td>
									<t-td>{{ item.hobby }}</t-td>
									<t-td>{{ item.id + 1 }}</t-td>
									<t-td>{{ item.name }}</t-td>
									<t-td>{{ item.age }}</t-td>
									<t-td>{{ item.hobby }}</t-td>
									<t-td>{{ item.id + 1 }}</t-td>
									<t-td>{{ item.id + 1 }}</t-td>
									<t-td>{{ item.name }}</t-td>
									<t-td>{{ item.age }}</t-td>
									<t-td>{{ item.hobby }}</t-td>
									<t-td>{{ item.id + 1 }}</t-td>
								</t-tr>
							</t-table>
						</view>
					</scroll-view>

樣式部分

        //設置寬度,定義成彈性盒模式,並且不換行。
        .scroll-view_H{
		width: 200%;
		display: flex;
		flex-wrap: nowrap;
	}


此時table就是可以左右滑動了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM