|
| 1 | +# Element-UI CRUD |
| 2 | + |
| 3 | +CRUD components for Element-UI (Vue). |
| 4 | + |
| 5 | +This is intended for use with Laravel's Resource Controllers: |
| 6 | + |
| 7 | +https://laravel.com/docs/5.5/controllers#resource-controllers |
| 8 | + |
| 9 | +However, it may be used in other HTTP applications if the same endpoints are implemented. |
| 10 | + |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Requires: |
| 15 | + |
| 16 | +``` |
| 17 | +npm install axios --save |
| 18 | +npm install vue --save |
| 19 | +npm install element-ui --save |
| 20 | +``` |
| 21 | + |
| 22 | +Install: |
| 23 | + |
| 24 | +``` |
| 25 | +npm install element-ui-crud --save |
| 26 | +``` |
| 27 | + |
| 28 | +Configuration: |
| 29 | + |
| 30 | +You must set Axios as your $http library: |
| 31 | + |
| 32 | +``` |
| 33 | +import Axios from 'axios' |
| 34 | +Vue.prototype.$http = Axios; |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | +## Components |
| 39 | + |
| 40 | +Element-UI CRUD is designed to be modular so that each component can be used on its own if desired. |
| 41 | + |
| 42 | +### ElCrud |
| 43 | + |
| 44 | +The primary component that provides full CRUD functionality. |
| 45 | + |
| 46 | +#### Example |
| 47 | + |
| 48 | +```vue |
| 49 | +<template> |
| 50 | + <div> |
| 51 | + <h1>Users</h1> |
| 52 | + <hr/> |
| 53 | + |
| 54 | + <el-crud endpoint="/api/users" |
| 55 | + :list="['id', 'name']" |
| 56 | + :create="['name']" |
| 57 | + :edit="['name']" |
| 58 | + :titles="{ 'id': 'ID', 'name': 'Name' }" |
| 59 | + <template slot="list" scope="scope"> |
| 60 | + <el-button size="small" type="primary" v-on:click="alert(scope.row)" icon="information"></el-button> |
| 61 | + </template> |
| 62 | + </el-crud> |
| 63 | + </div> |
| 64 | +</template> |
| 65 | +
|
| 66 | +<script> |
| 67 | + import ElCrud from "element-ui-crud" |
| 68 | +
|
| 69 | + export default { |
| 70 | + components: { ElCrud }, |
| 71 | + } |
| 72 | +</script> |
| 73 | +``` |
| 74 | + |
| 75 | +#### Over-riding/Customizing Display of Columns |
| 76 | + |
| 77 | +The display of columns can be over-ridden using Vue's Template/Slot system. The general format is "component.columnName". An example is below showing how to over-ride the "id" column in the "List" component. |
| 78 | + |
| 79 | +```vue |
| 80 | +<el-crud endpoint="/api/users" |
| 81 | + :list="['id', 'name']" |
| 82 | + :create="['name']" |
| 83 | + :edit="['name']" |
| 84 | + :titles="{ 'id': 'ID', 'name': 'Name' }" |
| 85 | + <template slot="list" scope="scope"> |
| 86 | + <el-button size="small" type="primary" v-on:click="console.log(scope.row)" icon="information"></el-button> |
| 87 | + </template> |
| 88 | + <template slot="list.id" scope="scope"> |
| 89 | + ID of user is {{ scope.row['id'] }} |
| 90 | + </template> |
| 91 | +</el-crud> |
| 92 | +``` |
| 93 | + |
| 94 | +If you plan on using a custom component on the Create or Edit component, you must bind the v-model as below: |
| 95 | + |
| 96 | +```vue |
| 97 | +<template slot="edit.data" scope="scope"> |
| 98 | + <code-editor v-model="scope.entity.data"></code-editor> |
| 99 | +</template> |
| 100 | +``` |
| 101 | + |
| 102 | +(Note that the component MUST support the use of v-model for this to work.) |
| 103 | + |
| 104 | +#### Supported Parameters |
| 105 | + |
| 106 | +- endpoint |
| 107 | + |
| 108 | + The root HTTP REST endpoint of your backend that provides CRUD functionality. |
| 109 | + Note that this should implement the same endpoints as Laravel's Resource Controller. |
| 110 | + |
| 111 | + - **Type:** string |
| 112 | + - **Example:** "/api/users" |
| 113 | + |
| 114 | +- primary-key (optional) |
| 115 | + |
| 116 | + The primary key to use on the List component. |
| 117 | + |
| 118 | + - **Type:** string |
| 119 | + - **Default:** "id" |
| 120 | + |
| 121 | +- list |
| 122 | + |
| 123 | + Fields that should be shown on the List component. |
| 124 | + |
| 125 | + - **Type:** array |
| 126 | + - **Example:** ["id", "name"] |
| 127 | + |
| 128 | +- create |
| 129 | + |
| 130 | + Fields that should be shown on the Create component. |
| 131 | + If not specified, create functionality will not be offered. |
| 132 | + |
| 133 | + - **Type:** array |
| 134 | + - **Example:** ["name"] |
| 135 | + |
| 136 | +- edit |
| 137 | + |
| 138 | + Fields that should be shown on the Edit component. |
| 139 | + If not specified, edit functionality will not be offered. |
| 140 | + |
| 141 | + - **Type:** array |
| 142 | + - **Example:** ["name"] |
| 143 | + |
| 144 | +- show-delete |
| 145 | + |
| 146 | + Whether "Delete" should be shown next to items in row. |
| 147 | + |
| 148 | + - **Type:** boolean |
| 149 | + - **Default:** true |
| 150 | + |
| 151 | +- show-refresh |
| 152 | + |
| 153 | + Whether "Refresh" button should be shown above table. |
| 154 | + |
| 155 | + - **Type:** boolean |
| 156 | + - **Default:** true |
| 157 | + |
| 158 | +- titles |
| 159 | + |
| 160 | + Titles to apply to List Columns and Create/Edit Forms. |
| 161 | + If not provided, the key for that column is used. |
| 162 | + |
| 163 | + - **Type:** Object |
| 164 | + - **Example:** { id: 'ID', name: 'Name' } |
| 165 | + |
| 166 | +- order (TODO) |
| 167 | + |
| 168 | + Titles to apply to List Columns and Create/Edit Forms. |
| 169 | + If not provided, the key for that column is used. |
| 170 | + |
| 171 | + - **Type:** Object |
| 172 | + - **Example:** { id: 'ID', name: 'Name' } |
| 173 | + |
| 174 | +- params |
| 175 | + |
| 176 | + Extra parameters that should be passed with every request. |
| 177 | + These will be passed in the query string. |
| 178 | + |
| 179 | + - **Type:** Object |
| 180 | + - **Example:** { where: 'user.type == "ADMIN' } |
| 181 | + |
| 182 | +- fields (TODO) |
| 183 | + |
| 184 | + Extra parameters that should be passed with every request. |
| 185 | + Can be used for filtering the results server-side. |
| 186 | + |
| 187 | + - **Type:** Object |
| 188 | + - **Example:** { level: 'admin' } |
| 189 | + |
| 190 | +- after |
| 191 | + |
| 192 | + Function to perform after Create/Edit. |
| 193 | + For example, after a edit is performed, you might wish to update a VueX store. |
| 194 | + |
| 195 | + - **Type:** function |
| 196 | + - **Example:** function(entity) { this.$store.dispatch('refreshUsers'); } |
| 197 | + |
| 198 | +- pagination |
| 199 | + |
| 200 | + If set, Pagination will be enabled. This must be handled server-side. |
| 201 | + The "limit" and "offset" parameters will be passed in the Query String. |
| 202 | + |
| 203 | + - **Type:** integer |
| 204 | + - **Default:** 0 |
| 205 | + - **Example:** 50 |
| 206 | + |
| 207 | +- create-size |
| 208 | + |
| 209 | + Size of the Create Dialog. |
| 210 | + |
| 211 | + - **Type:** string |
| 212 | + - **Default:** "small" |
| 213 | + - **Example:** "large" |
| 214 | + |
| 215 | +- edit-size |
| 216 | + |
| 217 | + Size of the Edit Dialog. |
| 218 | + |
| 219 | + - **Type:** string |
| 220 | + - **Default:** "small" |
| 221 | + - **Example:** "large" |
| 222 | + |
| 223 | +- delete-size |
| 224 | + |
| 225 | + Size of the Delete Dialog. |
| 226 | + |
| 227 | + - **Type:** string |
| 228 | + - **Default:** "tiny" |
| 229 | + - **Example:** "small" |
| 230 | + |
| 231 | +### ElList |
| 232 | + |
| 233 | +Component to display the Rows in a table. |
| 234 | + |
| 235 | +See [List.vue](src/List.vue) for a list of available parameters. |
| 236 | + |
| 237 | +### ElEdit |
| 238 | + |
| 239 | +Component to display the Edit Form. |
| 240 | + |
| 241 | +See [Edit.vue](src/Edit.vue) for a list of available parameters. |
| 242 | + |
| 243 | +### ElCreate |
| 244 | + |
| 245 | +Component to display the Create Form. |
| 246 | + |
| 247 | +See [Create.vue](src/Create.vue) for a list of available parameters. |
| 248 | + |
| 249 | +## Badges |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | + |
| 254 | +--- |
0 commit comments