-
Notifications
You must be signed in to change notification settings - Fork 67
lesson 16
In this lesson, we will start working on refactoring our MyVuetable
component to accept properties and make it work as the same.
As a summary, here are the list of properties that we are going to make:
- api-url
- fields
- multi-sort
- sort-order
- append-params
If you are new to Prop, check out the documentation on Vue.js Guide here.
First, we need to define that our component accepts those properties. We are going to borrow the same property names from Vuetable in this case.
// MyVuetable.vue
//...
export default {
name: 'my-vuetable',
components: {
//...
},
props: {
apiUrl: {
type: String,
required: true
},
fields: {
type: Array,
required: true
},
sortOrder: {
type: Array,
default() {
return []
}
},
appendParams: {
type: Object,
default() {
return {}
}
},
detailRowComponent: {
type: String
}
},
//...
}
Only the
api-url
andfields
properties are required. So, we marked it withrequired: true
.
Now, we modify the template to use our newly defined properties, like so.
// MyVuetable.vue
//...
<vuetable ref="vuetable"
:api-url="apiUrl"
:fields="fields"
pagination-path=""
:per-page="10"
:multi-sort="true"
:sort-order="sortOrder"
:append-params="appendParams"
detail-row-component="detailRowComponent"
//...
></vuetable>
Note
Theper_page
has been changed from20
to10
.
We need to clean up the following as well:
-
Looking at the
data
section, you will see that all the variables in this section are no longer needed as they will be passed in via our properties instead, so we can remove all of them here.// MyVuetable.vue // you can even remove the data section itself data () { return {} }, //...
-
The
import
statements ofFieldDefs
andDetailRow
are no longer needed here, so remove both of them.
Now we need to modify App.vue
, so that all necessary data are declared and pass into <my-vuetable>
via properties we've defined earlier. Here is what we need to do:
- Add
data
section and declare our variables - Import field definition in here
- Add prop to our App template
// App.vue
//
- Your first Vuetable
- Displaying more fields
- Cleaning up code
- Make change to field title
- Column alignment
- Format fields using
callback
option - Adding pagination
- Displaying pagination information
- Customizing Vuetable
- Make columns sortable
- Using special fields
- Adding Detail Row
- Adding Search Filter
- Moving Field Definitions to another file
- Passing Props to MyVuetable - Part 1
- Passing Props to MyVuetable - Part 2
- Passing Scoped Slot to MyVuetable
- Using Twitter's Bootstrap CSS with Vuetable
- Pagination for Twitter's Bootstrap