11<template >
2- <el-table class =" main" :data =" getArr((currentPage - 1) * 5 + 1, currentPage * 5)" border stripe
3- :default-sort =" { prop: 'date', order: 'descending' }" >
2+ <div class =" but" >
3+ <el-button type =" success" @click =" addItem" >Add</el-button >
4+ <el-button type =" danger" @click =" deleteItem" >Delete</el-button >
5+ </div >
6+ <el-table class =" main" :data =" currentData" border stripe :default-sort =" { prop: 'date', order: 'descending' }"
7+ @selection-change =" handleSelectionChange" >
48
59 <el-table-column type =" selection" width =" 55" />
610 <el-table-column fixed prop =" id" label =" id" sortable />
@@ -35,6 +39,11 @@ import { ref, computed } from 'vue'
3539import { useControlData } from ' @/stores/useControlData' ;
3640
3741let currentPage = ref (1 )
42+ let currentData = ref (computed (() => {
43+ return getArr ((currentPage .value - 1 ) * 5 + 1 , currentPage .value * 5 )
44+ }))
45+
46+ let nowSelected: any = [];
3847
3948const controlData = useControlData ()
4049controlData .setNewVal (js .products )
@@ -59,6 +68,31 @@ const getArr = (x: number, y: number) => {
5968const emitDetail = (index : number ) => {
6069 controlData .open (index )
6170
71+ }
72+
73+ const addItem = () => {
74+ controlData .pushNewItem ()
75+ controlData .open (controlData .data .at (- 1 ).id - 1 )
76+ controlData .checkState (true )
77+ }
78+
79+ const handleSelectionChange = (val : any ) => {
80+ nowSelected = []
81+ val .forEach ((element : any , index : number ) => {
82+ nowSelected [index ] = element .id
83+ });
84+ }
85+ const deleteItem = () => {
86+ console .log (nowSelected );
87+
88+ nowSelected .forEach ((id : number , index : number ) => {
89+ console .log (id );
90+
91+ controlData .idDelItem (id )
92+ console .log (controlData .data );
93+
94+ });
95+
6296}
6397 </script >
6498
@@ -67,11 +101,17 @@ const emitDetail = (index: number) => {
67101 display : inline-block ;
68102 width : 90vw ;
69103 margin-top : 75px ;
70- left : calc (50 vw - 45 vw );
104+ left : calc (5 vw );
71105}
72106
73107.demo-pagination-block {
74108 margin-top : 10px ;
75109 margin-left : 5vw ;
76110}
111+
112+ .but {
113+ position : absolute ;
114+ top : 30px ;
115+ left : calc (5vw );
116+ }
77117 </style >
0 commit comments