1
1
<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" >
4
8
5
9
<el-table-column type =" selection" width =" 55" />
6
10
<el-table-column fixed prop =" id" label =" id" sortable />
@@ -35,6 +39,11 @@ import { ref, computed } from 'vue'
35
39
import { useControlData } from ' @/stores/useControlData' ;
36
40
37
41
let 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 = [];
38
47
39
48
const controlData = useControlData ()
40
49
controlData .setNewVal (js .products )
@@ -59,6 +68,31 @@ const getArr = (x: number, y: number) => {
59
68
const emitDetail = (index : number ) => {
60
69
controlData .open (index )
61
70
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
+
62
96
}
63
97
</script >
64
98
@@ -67,11 +101,17 @@ const emitDetail = (index: number) => {
67
101
display : inline-block ;
68
102
width : 90vw ;
69
103
margin-top : 75px ;
70
- left : calc (50 vw - 45 vw );
104
+ left : calc (5 vw );
71
105
}
72
106
73
107
.demo-pagination-block {
74
108
margin-top : 10px ;
75
109
margin-left : 5vw ;
76
110
}
111
+
112
+ .but {
113
+ position : absolute ;
114
+ top : 30px ;
115
+ left : calc (5vw );
116
+ }
77
117
</style >
0 commit comments