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

easyui +vue v-slot 注意事项

https://www.jeasyui.com/demo-vue/main/index.php?plugin=DataGrid&theme=material-teal&dir=ltr&pitem=CheckBox%20Selection&sort=asc

接口说明

<template>
  <div>
    <h2>Checkbox Selection</h2>
    <DataGrid :data="data" style="height:250px">
      <GridColumn field="ck" :width="50" align="center">
        <template #header slot-scope="scope">
          <CheckBox v-model="allChecked" @checkedChange="onAllCheckedChange($event)"></CheckBox>
        </template>
        <template #body slot-scope="scope">
          <CheckBox v-model="scope" @checkedChange="onCheckedChange($event)"></CheckBox>
        </template>
      </GridColumn>
      <GridColumn field="itemid" title="Item ID"></GridColumn>
      <GridColumn field="name" title="Name" width="30%"></GridColumn>
      <GridColumn field="listprice" title="List Price" align="right"></GridColumn>
      <GridColumn field="unitcost" title="Unit Cost" align="right"></GridColumn>
      <GridColumn field="status" title="Status" align="center"></GridColumn>
    </DataGrid>
    <p>Checked Items: {{checkedRows.map(row=>row.code).join(',')}}</p>
  </div>
</template>

<script setup lang="js">
import {DataGrid,GridColumn,CheckBox} from "v3-easyui";
</script>

<script lang="js">
export default {
  data() {
    return {
      data:  [
        {
          code: "FI-SW-01",
          name: "Koi",
          unitcost: 10.0,
          status: "P",
          listprice: 36.5,
          attr: "Large",
          itemid: "EST-1",
          selected: true
        },
        {
          code: "K9-DL-01",
          name: "Dalmation",
          unitcost: 12.0,
          status: "P",
          listprice: 18.5,
          attr: "Spotted Adult Female",
          itemid: "EST-10"
        },
        {
          code: "RP-SN-01",
          name: "Rattlesnake",
          unitcost: 12.0,
          status: "P",
          listprice: 38.5,
          attr: "Venomless",
          itemid: "EST-11"
        },
        {
          code: "RP-SN-01",
          name: "Rattlesnake",
          unitcost: 12.0,
          status: "P",
          listprice: 26.5,
          attr: "Rattleless",
          itemid: "EST-12"
        },
        {
          code: "RP-LI-02",
          name: "Iguana",
          unitcost: 12.0,
          status: "P",
          listprice: 35.5,
          attr: "Green Adult",
          itemid: "EST-13"
        },
        {
          code: "FL-DSH-01",
          name: "Manx",
          unitcost: 12.0,
          status: "P",
          listprice: 158.5,
          attr: "Tailless",
          itemid: "EST-14"
        },
        {
          code: "FL-DSH-01",
          name: "Manx",
          unitcost: 12.0,
          status: "P",
          listprice: 83.5,
          attr: "With tail",
          itemid: "EST-15"
        },
        {
          code: "FL-DLH-02",
          name: "Persian",
          unitcost: 12.0,
          status: "P",
          listprice: 23.5,
          attr: "Adult Female",
          itemid: "EST-16"
        },
        {
          code: "FL-DLH-02",
          name: "Persian",
          unitcost: 12.0,
          status: "P",
          listprice: 89.5,
          attr: "Adult Male",
          itemid: "EST-17"
        },
        {
          code: "AV-CB-01",
          name: "Amazon Parrot",
          unitcost: 92.0,
          status: "P",
          listprice: 63.5,
          attr: "Adult Male",
          itemid: "EST-18"
        }
      ],
      allChecked: false,
      rowClicked: false
    };
  },
  computed: {
    checkedRows() {
      return this.data.filter(row => row.selected);
    }
  },
  methods: {
    onAllCheckedChange(checked) {
      if (this.rowClicked) {
        return;
      }
      this.data = this.data.map(row => {
        return Object.assign({}, row, {
          selected: checked
        });
      });
    },
    onCheckedChange(checked) {
      this.allChecked = this.checkedRows.length === this.data.length;
      this.rowClicked = true;
      this.$nextTick(() => (this.rowClicked = false));
    }
  }
};
</script>

兼容型修改 v3-easyui,修改的示例代码,兼容 vue 最新版本

在这里插入图片描述

更准确的修改 , 引用网图

在这里插入图片描述

vue3 的语法 最终生效没有报错,查了一遍书 … …


<template>
  <div>
    <h2>Checkbox Selection</h2>
    <DataGrid :data="data"
              style="width: 100%;height: 100%;"
              :dblclickToEdit="true"
              selectionMode="row"
              :pagination="true"
              :total="data.length"
              :pageSize="10"
              editMode="row"
              @editEnd="onEditEnd($event)"
              @cellClick="onCellClick($event)"
              :clickToEdit="false">
      <GridColumn field="ck" :width="50" align="center">
        <template v-slot:header>
          <CheckBox v-model="allChecked" @checkedChange="onAllCheckedChange($event)"></CheckBox>
        </template>
        <template v-slot:body="scope">
          <CheckBox  v-model="scope.row.selected" @checkedChange="onCheckedChange($event)"></CheckBox>
        </template>
      </GridColumn>
      <GridColumn field="itemid" title="Item ID"></GridColumn>
      <GridColumn field="name" title="Name" width="30%"></GridColumn>
      <GridColumn field="listprice" title="List Price" align="right" :editable="true"></GridColumn>
      <GridColumn field="unitcost" title="Unit Cost" align="right"></GridColumn>
      <GridColumn field="status" title="Status" align="center"></GridColumn>
    </DataGrid>
  </div>
</template>

<script setup lang="js">
import {DataGrid,GridColumn,CheckBox,Panel,Pagination} from "v3-easyui";
</script>

<script lang="js">
export default {
  data() {
    return {
      data:  [
        {
          code: "FI-SW-01",
          name: "Koi",
          unitcost: 10.0,
          status: "P",
          listprice: 36.5,
          attr: "Large",
          itemid: "EST-1",
          selected: false
        },
        {
          code: "K9-DL-01",
          name: "Dalmation",
          unitcost: 12.0,
          status: "P",
          listprice: 18.5,
          attr: "Spotted Adult Female",
          itemid: "EST-10",
          selected: false
        },
        {
          code: "RP-SN-01",
          name: "Rattlesnake",
          unitcost: 12.0,
          status: "P",
          listprice: 38.5,
          attr: "Venomless",
          itemid: "EST-11",
          selected: false
        },
        {
          code: "RP-SN-01",
          name: "Rattlesnake",
          unitcost: 12.0,
          status: "P",
          listprice: 26.5,
          attr: "Rattleless",
          itemid: "EST-12",
          selected: false
        },
        {
          code: "RP-LI-02",
          name: "Iguana",
          unitcost: 12.0,
          status: "P",
          listprice: 35.5,
          attr: "Green Adult",
          itemid: "EST-13",
          selected: false
        },
        {
          code: "FL-DSH-01",
          name: "Manx",
          unitcost: 12.0,
          status: "P",
          listprice: 158.5,
          attr: "Tailless",
          itemid: "EST-14",
          selected: false
        },
        {
          code: "FL-DSH-01",
          name: "Manx",
          unitcost: 12.0,
          status: "P",
          listprice: 83.5,
          attr: "With tail",
          itemid: "EST-15",
          selected: false
        },
        {
          code: "FL-DLH-02",
          name: "Persian",
          unitcost: 12.0,
          status: "P",
          listprice: 23.5,
          attr: "Adult Female",
          itemid: "EST-16",
          selected: false
        },
        {
          code: "FL-DLH-02",
          name: "Persian",
          unitcost: 12.0,
          status: "P",
          listprice: 89.5,
          attr: "Adult Male",
          itemid: "EST-17",
          selected: false
        },
        {
          code: "AV-CB-01",
          name: "Amazon Parrot",
          unitcost: 92.0,
          status: "P",
          listprice: 63.5,
          attr: "Adult Male",
          itemid: "EST-18",
          selected: false
        }
      ],
      allChecked: false,
      rowClicked: false
    };
  },
  computed: {
    checkedRows() {
      return this.data.filter(row => row.selected);
    }
  },
  methods: {
    onPageChange(event){
      console.log(event);
    },
    onAllCheckedChange(checked) {
      if (this.rowClicked) {
        return;
      }
      this.data = this.data.map(row => {
        return Object.assign({}, row, {
          selected: checked
        });
      });
    },
    onEditEnd(event){
      console.log(event);
    },
    onCellClick(event){
      console.log(event);
    },
    onCheckedChange(checked) {
      this.allChecked = this.checkedRows.length === this.data.length;
      this.rowClicked = true;
      this.$nextTick(() => (this.rowClicked = false));
    }
  }
};
</script>

最终可用的组件

绑定数据以后可以根据menu 动态更新分类数据


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

相关文章:

  • Android修行手册 - 移动端几种常用动画方案对比
  • 京东大数据治理探索与实践 | 京东零售技术实践
  • git命令恢复/还原某个文件、删除远程仓库中的文件
  • C的编译过程有哪些步骤?
  • 代码随想录 day52 第十一章 图论part03
  • 如何学习Trustzone
  • Grafana+Prometheus监控篇-Nginx
  • C#中,Thread和Task的区别
  • 人工智能基础-opencv-图像处理篇
  • 第二届新生程序设计竞赛热身赛(C语言)
  • File和InputStream,OutputStream
  • JavaEE初阶---网络原理值TCP篇(三)
  • gradle下载的jar包,源码出现Decompiled .class file, bytecode version
  • nginx监控指标有哪些
  • AI开发-三方库-torch-torchvision
  • Redis学习:BigKey、缓存双写一致性更新策略和案例
  • 小土堆学习笔记15:搭建小实战和Sequential的使用
  • w~自动驾驶~合集4
  • 【深度学习】DreamClear:提升图片分辨率的模型
  • git cherry-pick 小技巧
  • 【日志】初学顺序表
  • 基于springboot+vue实现的网上预约挂号管理系统 (源码+L文+ppt)4-104
  • 如何应对Oracle SQL语句的数据去重问题,应该考虑哪几个方面?
  • BFS-专题
  • 【Python】Python自习课:第一个python程序
  • GPT原理;ChatGPT 等类似的问答系统工作流程如下;当用户向 ChatGPT 输入一个问题后:举例说明;ChatGPT不是通过索引搜索的传统知识库