Vuestic 数据表格 使用demo

ts 复制代码
<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 属性配置设置

python 复制代码
<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

可以达到预期

相关推荐
小曲曲10 分钟前
接口上传视频和oss直传视频到阿里云组件
javascript·阿里云·音视频
学不会•1 小时前
css数据不固定情况下,循环加不同背景颜色
前端·javascript·html
EasyNTS2 小时前
H.264/H.265播放器EasyPlayer.js视频流媒体播放器关于websocket1006的异常断连
javascript·h.265·h.264
活宝小娜4 小时前
vue不刷新浏览器更新页面的方法
前端·javascript·vue.js
程序视点4 小时前
【Vue3新工具】Pinia.js:提升开发效率,更轻量、更高效的状态管理方案!
前端·javascript·vue.js·typescript·vue·ecmascript
coldriversnow4 小时前
在Vue中,vue document.onkeydown 无效
前端·javascript·vue.js
我开心就好o4 小时前
uniapp点左上角返回键, 重复来回跳转的问题 解决方案
前端·javascript·uni-app
开心工作室_kaic5 小时前
ssm161基于web的资源共享平台的共享与开发+jsp(论文+源码)_kaic
java·开发语言·前端
刚刚好ā5 小时前
js作用域超全介绍--全局作用域、局部作用、块级作用域
前端·javascript·vue.js·vue
沉默璇年6 小时前
react中useMemo的使用场景
前端·react.js·前端框架