Slide 7
Slide 7 text
.PEFMΛఆٛ͢Δ
import { Model } from '@vuex-orm/core'
class User extends Model {
static entity = 'users'
static fields () {
return {
id: this.attr(null),
name: this.string(''),
posts: this.hasMany(Post, 'user_id')
}
}
}
import { Model } from '@vuex-orm/core'
class Post extends Model {
static entity = 'posts'
static fields () {
return {
id: this.attr(null),
user_id: this.attr(null),
title: this.string(''),
user: this.belongsTo(User, 'user_id')
}
}