File tree 7 files changed +70
-22
lines changed
7 files changed +70
-22
lines changed Original file line number Diff line number Diff line change 7
7
"build" : " vue-cli-service build"
8
8
},
9
9
"dependencies" : {
10
+ "@vuex-orm/core" : " ^0.36.4" ,
10
11
"vue" : " ^3.0.0" ,
11
12
"vuex" : " ^4.0.0-0"
12
13
},
Original file line number Diff line number Diff line change 1
1
<template >
2
- <HelloWorld msg =" Welcome to Your Vue.js + TypeScript App" />
2
+ <h1 >state entities</h1 >
3
+ <pre >{{ entities }}</pre >
3
4
</template >
4
5
5
6
<script lang="ts">
6
- import { defineComponent } from ' vue'
7
- import HelloWorld from ' ./components/HelloWorld.vue'
7
+ import { defineComponent , ref , onMounted } from ' vue'
8
+ import { useStore } from ' vuex'
9
+ import { User } from ' @/models'
8
10
9
11
export default defineComponent ({
10
12
name: ' App' ,
11
- components: {
12
- HelloWorld ,
13
+ setup() {
14
+ const { state } = useStore ()
15
+ const entities = ref (state .entities )
16
+
17
+ onMounted (async () => {
18
+ await User .insert ({
19
+ data: {
20
+ id: 1 ,
21
+ name: ' John Doe' ,
22
+
23
+ },
24
+ })
25
+ })
26
+
27
+ return {
28
+ entities ,
29
+ }
13
30
},
14
31
})
15
32
</script >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { Model } from '@vuex-orm/core'
2
+
3
+ export class User extends Model {
4
+ static entity = 'users'
5
+
6
+ static fields ( ) {
7
+ return {
8
+ id : this . attr ( null ) ,
9
+ name : this . attr ( '' ) ,
10
+ email : this . attr ( '' ) ,
11
+ }
12
+ }
13
+ }
14
+
15
+ export class Post extends Model {
16
+ static entity = 'posts'
17
+
18
+ static fields ( ) {
19
+ return {
20
+ id : this . attr ( null ) ,
21
+ user_id : this . attr ( null ) ,
22
+ title : this . attr ( '' ) ,
23
+ body : this . attr ( '' ) ,
24
+ published : this . attr ( false ) ,
25
+ author : this . belongsTo ( User , 'user_id' ) ,
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change 1
1
import { createStore } from 'vuex'
2
+ import VuexORM from '@vuex-orm/core'
3
+ import * as models from '@/models'
4
+
5
+ const database = new VuexORM . Database ( )
6
+ for ( let model of Object . values ( models ) ) database . register ( model )
2
7
3
8
export default createStore ( {
4
9
state : { } ,
5
10
mutations : { } ,
6
11
actions : { } ,
7
12
modules : { } ,
13
+ plugins : [ VuexORM . install ( database ) ] ,
8
14
} )
Original file line number Diff line number Diff line change 1
1
{
2
2
"compilerOptions" : {
3
- "target" : " es5 " ,
3
+ "target" : " es6 " ,
4
4
"module" : " esnext" ,
5
5
"strict" : true ,
6
6
"jsx" : " preserve" ,
Original file line number Diff line number Diff line change 505
505
resolved "https://registry.yarnpkg.com/@vue/web-component-wrapper/-/web-component-wrapper-1.3.0.tgz#b6b40a7625429d2bd7c2281ddba601ed05dc7f1a"
506
506
integrity sha512-Iu8Tbg3f+emIIMmI2ycSI8QcEuAUgPTgHwesDU1eKMLE4YC/c/sFbGc70QgMq31ijRftV0R7vCm9co6rldCeOA==
507
507
508
+ " @vuex-orm/core@^0.36.4 " :
509
+ version "0.36.4"
510
+ resolved "https://registry.yarnpkg.com/@vuex-orm/core/-/core-0.36.4.tgz#9e2b1b8dfd74c2a508f1862ffa3e4a2c1e4cc60c"
511
+ integrity sha512-Wkq1G+FtcEQ4LbhEZUZalhuErb2nY2nuBo2UeGVpbVKkMss5piJhw7bt5TpWecDNmIUc2BzaenDDqm08AAe7Hw==
512
+ dependencies :
513
+ normalizr "^3.6.0"
514
+
508
515
" @webassemblyjs/[email protected] " :
509
516
version "1.9.0"
510
517
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"
@@ -4562,6 +4569,11 @@ normalize-url@^3.0.0:
4562
4569
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
4563
4570
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
4564
4571
4572
+ normalizr@^3.6.0 :
4573
+ version "3.6.1"
4574
+ resolved "https://registry.yarnpkg.com/normalizr/-/normalizr-3.6.1.tgz#d367ab840e031ff382141b8d81ce279292ff69fe"
4575
+ integrity sha512-8iEmqXmPtll8PwbEFrbPoDxVw7MKnNvt3PZzR2Xvq9nggEEOgBlNICPXYzyZ4w4AkHUzCU998mdatER3n2VaMA==
4576
+
4565
4577
npm-run-path@^2.0.0 :
4566
4578
version "2.0.2"
4567
4579
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
You can’t perform that action at this time.
0 commit comments