Skip to content

Commit c137c01

Browse files
committed
docs(configuration): example of extra methods and computed properties
Closes #151
1 parent 644ab4e commit c137c01

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

docs/content/en/configuration.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class Model extends BaseModel {
4040

4141
## Creating the Domain Models
4242

43-
Now let's create our domain models that extends the base model. We can create as many models as you like.
43+
Now let's create our domain models that extends the base model. We can create as many models as we like.
4444

4545
Each model must implement:
4646
- `resource` - The resource route of the model.
@@ -59,6 +59,30 @@ export default class User extends Model {
5959

6060
This **User** model will make request to `/users` route as defined in `resource`.
6161

62+
We can also add extra methods and computed properties:
63+
64+
```js{}[~/models/User.js]
65+
import Model from './Model'
66+
67+
export default class User extends Model {
68+
// Set the resource route of the model
69+
resource() {
70+
return 'users'
71+
}
72+
73+
// Computed properties are reactive -> user.fullName
74+
// Make sure to use "get" prefix
75+
get fullName () {
76+
return `${this.firstname} ${this.lastname}`
77+
}
78+
79+
// Method -> user.makeBirthday()
80+
makeBirthday() {
81+
return this.age += 1
82+
}
83+
}
84+
```
85+
6286
## Changing the Primary Key
6387

6488
<alert type="info">By default, the `primaryKey` is set to `id`.</alert>
@@ -154,6 +178,17 @@ export default class User extends Model {
154178
posts() {
155179
return this.hasMany(Post)
156180
}
181+
182+
// Computed properties are reactive -> user.fullName
183+
// Make sure to use "get" prefix
184+
get fullName () {
185+
return `${this.firstname} ${this.lastname}`
186+
}
187+
188+
// Method -> user.makeBirthday()
189+
makeBirthday() {
190+
return this.age += 1
191+
}
157192
}
158193
```
159194

0 commit comments

Comments
 (0)