基于vue3開發(fā)mobile-table適用于移動(dòng)端表格
mobile-table 適用于移動(dòng)端表格
基于
vue3開發(fā)的移動(dòng)端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 屬性說明
| 屬性名 | 說明 | 類型 | 默認(rèn)值 | 說明 |
|---|---|---|---|---|
| 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 屬性說明
| 屬性名 | 說明 | 類型 | 默認(rèn)值 | 說明 |
|---|---|---|---|---|
| label | 對(duì)應(yīng)列名稱 | string | ‘’ | |
| prop | 對(duì)應(yīng)列字段 | string | ‘’ | |
| width | 對(duì)應(yīng)列的寬度 | number | auto | |
| sort | 對(duì)應(yīng)列是否開啟排序 | boolean | false | |
| align | 對(duì)應(yīng)列的對(duì)齊方式 | 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適用于移動(dòng)端表格的文章就介紹到這了,更多相關(guān)vue3 mobile-table移動(dòng)端表格內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue2.0實(shí)戰(zhàn)之使用vue-cli搭建項(xiàng)目(2)
這篇文章主要為大家詳細(xì)介紹了vue2.0實(shí)戰(zhàn)第二篇使用vue-cli搭建項(xiàng)目,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03
vue出現(xiàn)Uncaught SyntaxError:Unexpected token問題及解決
這篇文章主要介紹了vue出現(xiàn)Uncaught SyntaxError:Unexpected token問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04
Vue3動(dòng)態(tài)組件component不生效問題解決方法
動(dòng)態(tài)組件component是Vue中非常實(shí)用的一個(gè)功能,它可以根據(jù)條件動(dòng)態(tài)切換不同的組件,在Vue3中使用方法和Vue2基本一致,在vue3使用component動(dòng)態(tài)組件展示組件時(shí),組件就是不展示顯示空白,所以本文記錄了Vue3動(dòng)態(tài)組件component不生效問題解決方法,需要的朋友可以參考下2024-08-08
詳解Vue-cli3 項(xiàng)目在安卓低版本系統(tǒng)和IE上白屏問題解決
這篇文章主要介紹了Vue-cli3 項(xiàng)目在安卓低版本系統(tǒng)和 IE 上白屏問題解決,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-04-04

