基于vue3開發(fā)mobile-table適用于移動端表格
更新時間:2024年03月26日 08:27:39 作者:Taoqun
這篇文章主要給大家介紹了關(guān)于如何基于vue3開發(fā)mobile-table適用于移動端表格的相關(guān)資料,需要的朋友可以參考下
mobile-table 適用于移動端表格
基于
vue3開發(fā)的移動端table表格組件
安裝
npm i mobile-table // or yarn add mobile-table
使用
// 導(dǎo)入組件
import { MobileTable, MobileTableColumn } from "mobile-table";
// 導(dǎo)入樣式
import "mobile-table/lib/style.css";
預(yù)覽


MobileTable 屬性說明
| 屬性名 | 說明 | 類型 | 默認值 | 說明 |
|---|---|---|---|---|
| data | table 數(shù)據(jù) | Array | Array | |
| sortKey | 排序字段 | string | ‘’ | |
| sortType | 排序類型 | number | 0 | |
| paging | 是開啟分頁 | boolean | false | |
| pageIndex | 分頁索引 | number | 1 | |
| pageTotal | 總分頁數(shù) | number | 1 |
MobileTable 事件說明
| 方法 | 說明 | 類型 | 說明 |
|---|---|---|---|
| sortChange | 排序字段和排序方法 變化 | Function | ({ sortKey: string, sortType: number })=> void |
| pageChange | pageIndex 分頁變化 | Function | (index: number)=> void |
MobileTableColumn 屬性說明
| 屬性名 | 說明 | 類型 | 默認值 | 說明 |
|---|---|---|---|---|
| label | 對應(yīng)列名稱 | string | ‘’ | |
| prop | 對應(yīng)列字段 | string | ‘’ | |
| width | 對應(yīng)列的寬度 | number | auto | |
| sort | 對應(yīng)列是否開啟排序 | boolean | false | |
| align | 對應(yīng)列的對齊方式 | string | left | left center right |
基本用法
<template>
<MobileTable :data="data" >
<MobileTableColumn name="姓名" prop="name" />
<MobileTableColumn name="年齡" prop="age" />
<MobileTableColumn name="性別" prop="sex">
<template #default="scope">
<div>{{ scope.row.sex === 1 ? "男" : "女" }}</div>
</template>
</MobileTableColumn>
</MobileTable>
</template>
<script setup>
// 引入組件
import { MobileTable, MobileTableColumn } from "mobile-table";
import "mobile-table/lib/style.css";
import { ref } from "vue";
// 表格數(shù)據(jù)
const data = ref([
{
name: "張三",
age: 18,
sex: 1,
},
{
name: "李四",
age: 18,
sex: 1,
},
{
name: "王小紅",
age: 18,
sex: 2,
},
]);
</script>
<style scoped></style>所有配置 支持分頁 支持排序
<template>
<MobileTable
:data="data"
:sortKey="sortKey"
:sortType="sortType"
:paging="isShowPaging"
:pageIndex="pageIndex"
:pageTotal="pageTotal"
@sortChange="onSortChange"
@pageChange="onPageChange"
>
<MobileTableColumn name="姓名" prop="name" />
<MobileTableColumn name="年齡" prop="age" :sort="true" />
<MobileTableColumn name="性別" prop="sex">
<template #default="scope">
<div>{{ scope.row.sex === 1 ? "男" : "女" }}</div>
</template>
</MobileTableColumn>
</MobileTable>
</template>
<script setup>
import { MobileTable, MobileTableColumn } from "mobile-table";
import "mobile-table/lib/style.css";
import { ref } from "vue";
// 表格數(shù)據(jù)
const data = ref([
{
name: "張三",
age: 18,
sex: 1,
},
{
name: "李四",
age: 18,
sex: 1,
},
{
name: "王小紅",
age: 18,
sex: 2,
},
]);
// 排序
const sortKey = ref("name");
const sortType = ref(1);
// 分頁
const isShowPaging = ref(true);
const pageIndex = ref(1);
const pageTotal = ref(12);
// 修改排序
function onSortChange(option = {}) {
sortKey.value = option.sortKey;
sortType.value = option.sortType;
}
// 修改分頁
function onPageChange(index) {
pageIndex.value = index;
}
</script>
<style scoped></style>總結(jié)
到此這篇關(guān)于如何基于vue3開發(fā)mobile-table適用于移動端表格的文章就介紹到這了,更多相關(guān)vue3 mobile-table移動端表格內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文讀懂vue動態(tài)屬性數(shù)據(jù)綁定(v-bind指令)
這篇文章主要介紹了vue動態(tài)屬性數(shù)據(jù)綁定(v-bind指令)的相關(guān)資料,文中講解非常細致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
Vue3 computed初始化獲取設(shè)置值實現(xiàn)示例
這篇文章主要為大家介紹了Vue3 computed初始化以及獲取值設(shè)置值實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10
vue組件文檔(.md)中如何自動導(dǎo)入示例(.vue)詳解
這篇文章主要給大家介紹了關(guān)于vue組件文檔(.md)中如何自動導(dǎo)入示例(.vue)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01
vue.js 1.x與2.0中js實時監(jiān)聽input值的變化
這篇文章主要介紹了vue.js 1.x與vue.js2.0中js實時監(jiān)聽input值的變化的相關(guān)資料,文中介紹的非常詳細,對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-03-03

