当前位置: 首页 > article >正文

Vuestic 数据表格 使用demo

<template>
  <br>
  <div class="grid sm:grid-cols-3 gap-6 mb-6">
    <VaButton @click="()=>{
      for(const it in this.selectedItems){
        console.log(this.selectedItems);
      }
    }">参数设置</VaButton>
    <VaButton>参数刷新</VaButton>
  </div>
  <br>
  <VaDataTable
    class="table-inline"
    v-model="selectedItems"
    :items="items"
    :columns="columns"
    selectable
    :per-page="perPage"
    :current-page="CurrentPage"
    @selection-change="selectedItemsEmitted = $event.currentSelectedItems"
  >
    <template
      v-for="item in inputList"
      :key="item"
      #[`cell(${item})`]="{ value, row }"
    >
      <div>
        <VaValue>
          <VaInput
            :model-value="value"
            @change="($event) => {
              row.rowData[item] = $event.target.value;
            }"
          />
        </VaValue>
      </div>
    </template>
    <template v-for="item in statusList" :key="item" #[`cell(${item})`]="{ value, row }"></template>
    <template v-for="item in selectList" :key="item" #[`cell(${item})`]="{ value, row }">
    </template>
    <template #bodyAppend>
      <tr>
        <td colspan="6">
          <div class="flex justify-center mt-4">
            <VaPagination
              v-model="CurrentPage"
              :pages="pages"
            />
          </div>
        </td>
      </tr>
    </template>
  </VaDataTable>
</template>

<script>
import { defineComponent } from "vue";
import {VaButton, VaInput, VaValue} from "vuestic-ui";

export default defineComponent({
  components: {VaInput, VaValue, VaButton},
  data() {
    const items = [
      {
        id: 1,
        name: "Leanne Graham",
        username: "Bret",
        email: "Sincere@april.biz",
        phone: "1-770-736-8031 x56442",
      },
      {
        id: 2,
        name: "Ervin Howell",
        username: "Antonette",
        email: "Shanna@melissa.tv",
        phone: "010-692-6593 x09125",
      },
      {
        id: 3,
        name: "Clementine Bauch",
        username: "Samantha",
        email: "Nathan@yesenia.net",
        phone: "1-463-123-4447",
      },
      {
        id: 4,
        name: "Patricia Lebsack",
        username: "Karianne",
        email: "Julianne.OConner@kory.org",
        phone: "493-170-9623 x156",
      },
      {
        id: 5,
        name: "Chelsey Dietrich",
        username: "Kamren",
        email: "Lucio_Hettinger@annie.ca",
        phone: "(254)954-1289",
      },
    ];

    const columns = [
      { key: "id", sortable: true },
      { key: "username", sortable: true },
      { key: "name", sortable: true },
      { key: "email", sortable: true },
      { key: "phone", sortable: true },
    ];

    return {
      inputList:["email","phone"],
      items,
      columns,
      perPage:10,
      CurrentPage: 1,
      selectedItems: [],
      selectedItemsEmitted: [],
      selectMode: "multiple",
      selectedColor: "primary",
    };
  },

  methods: {
    unselectItem(item) {
      this.selectedItems = this.selectedItems.filter(
        (selectedItem) => selectedItem !== item
      );
    },
  },
  computed: {
    pages() {
      console.log(this.items.length);
      return this.perPage && this.perPage !== 0
        ? Math.ceil(this.items.length / this.perPage)
        : this.items.length;
    },
  },
});
</script>

使用的最新的模板进行修改时发行,示例代码中有些地方不兼容,进行修改

通用参数数据表的模板

在这里插入图片描述

样式在做调整

整合以后,后端就不在时CGI了,直接通过RESETFULL 接口传输数据,json格式是真的香

https://vuejs.org/guide/components/props

props 属性配置设置

<template>
  <crud :items="mut_items.table" :columns="columns" :per-page="perPage" :input-list="input_list"
        @refresh_params="refresh" @set_params=null></crud>
</template>

<script lang="ts">
import {defineComponent, reactive} from "vue";
import Crud from "@/components/util/crud.vue";
const items = [
  {
    id: 1,
    name: "Leanne Graham",
    username: "Bret",
    email: "Sincere@april.biz",
    phone: "1-770-736-8031 x56442",
  },
  {
    id: 2,
    name: "Ervin Howell",
    username: "Antonette",
    email: "Shanna@melissa.tv",
    phone: "010-692-6593 x09125",
  },
  {
    id: 3,
    name: "Clementine Bauch",
    username: "Samantha",
    email: "Nathan@yesenia.net",
    phone: "1-463-123-4447",
  },
  {
    id: 4,
    name: "Patricia Lebsack",
    username: "Karianne",
    email: "Julianne.OConner@kory.org",
    phone: "493-170-9623 x156",
  },
  {
    id: 5,
    name: "Chelsey Dietrich",
    username: "Kamren",
    email: "Lucio_Hettinger@annie.ca",
    phone: "(254)954-1289",
  },
];

export default defineComponent({
  components: {Crud},
  data(){
    const input_list = ["name"];
    const columns = [
      { key: "id", sortable: true },
      { key: "username", sortable: true },
      { key: "name", sortable: true },
      { key: "email", sortable: true },
      { key: "phone", sortable: true },
    ];
    return {
      counts:0,
      mut_items:reactive({table:items}),
      columns,
      input_list,
      perPage: 10,
    }
  },
  methods:{
    refresh(selected){
      this.mut_items.table.push({ id: 5,
        name: "Chelsey Dietrich",
        username: "Kamren",
        email: "Lucio_Hettinger@annie.ca",
        phone: "(254)954-1289"});
    }
  }
});

父组件的使用方法

使用响应式数据

mut_items:reactive({table:items})

在使用route 修改路由,获取参数分类

书上说Vue 的设计思路 大体上 View -> [ViewModle] -> Modle

在这里插入图片描述

可以达到预期


http://www.kler.cn/a/377498.html

相关文章:

  • 单链表的实现(数据结构)
  • 轻松理解操作系统 - 轻松了解 inode 是如何管理文件的
  • JMeter与大模型融合应用之jmeter.properties配置文件新增配置
  • MYSQL安装(ubuntu系统)
  • Unity照片墙效果
  • Go:接口和反射
  • HTML前端页面设计静态网站
  • [NOIP2008 普及组] 排座椅
  • 【Redis:原理、架构与应用】
  • 中阳量化交易模型的探索与发展:科技引领金融未来
  • 东方娱乐周刊
  • 注册页面设计(表单基础)
  • 【机器学习】机器学习与成像技术:开启智能视觉的新篇章
  • Zypher Research:服务器抽象叙事,GameFi 赛道的下一个热点?
  • openssl-ecparam 命令手册
  • LeetCode (206单链表反转)
  • React + Vite + TypeScript + React router项目搭建教程
  • 以客户为导向在开源 AI 智能名片 2 + 1 链动模式 S2B2C 商城小程序内容创作中的实践与价值
  • 【缓存与加速技术实践】NoSQL之Redis部署安装与基础命令
  • 【LwIP源码学习4】主线程tcpip_thread
  • 1011:甲流疫情死亡率
  • 【零售和消费品&存货】价格标签检测系统源码&数据集全套:改进yolo11-RFAConv
  • 地平线 3D 目标检测 bev_sparse 参考算法-V1.0
  • TOEIC 词汇专题:饭店住宿篇
  • Docker篇(基础命令)
  • 【ChatGPT】让ChatGPT在回答中附带参考文献与来源