Skip to content

Commit b4b98ec

Browse files
committed
chore(dev): vuex 4 demo
1 parent b9133d4 commit b4b98ec

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

packages/shell-dev-vue3/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"@vue-devtools/shell-host": "^0.0.0",
1111
"core-js": "^3.6.4",
1212
"vue": "^3.0.2",
13-
"vue-router": "^4"
13+
"vue-router": "^4",
14+
"vuex": "^4.0.1"
1415
},
1516
"devDependencies": {
1617
"@vue/compiler-sfc": "^3.0.0-beta.15",

packages/shell-dev-vue3/src/App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export default {
8585
<inline />
8686
<global />
8787

88+
<h2>Store</h2>
89+
<div>
90+
{{ $store.getters.answer }}
91+
{{ $store.getters.twoFoo }}
92+
</div>
93+
8894
<nav>
8995
<router-link to="/p1">
9096
page 1

packages/shell-dev-vue3/src/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRouter, createWebHashHistory } from 'vue-router'
33
import App from './App.vue'
44
import App3 from './App3.vue'
55
import TestPlugin from './devtools-plugin'
6+
import store from './store'
67

78
// eslint-disable-next-line no-extend-native
89
Array.prototype.foo = 'bar'
@@ -26,8 +27,9 @@ const app = createApp(App)
2627
app.component('global', {
2728
render: () => 'I\'m a global component'
2829
})
29-
app.use(TestPlugin)
3030
app.use(router)
31+
app.use(store)
32+
app.use(TestPlugin)
3133
app.mount('#app')
3234

3335
createApp({

packages/shell-dev-vue3/src/store.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { createStore } from 'vuex'
2+
3+
const store = createStore({
4+
state () {
5+
return {
6+
rootState: 'root'
7+
}
8+
},
9+
getters: {
10+
answer: () => 42
11+
},
12+
modules: {
13+
nested: {
14+
state () {
15+
return {
16+
foo: 'bar'
17+
}
18+
},
19+
getters: {
20+
twoFoo: state => state.foo.repeat(2)
21+
}
22+
},
23+
namespacedModule: {
24+
namespaced: true,
25+
state () {
26+
return {
27+
count: 0
28+
}
29+
},
30+
getters: {
31+
doubleCount: state => state.count * 2,
32+
tripleCount: state => state.count * 3
33+
},
34+
modules: {
35+
animals: {
36+
namespaced: true,
37+
state () {
38+
return {
39+
cat: 'Meow'
40+
}
41+
},
42+
getters: {
43+
dog: () => 'Waf'
44+
}
45+
}
46+
}
47+
}
48+
}
49+
})
50+
51+
export default store

yarn.lock

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,11 +1723,6 @@
17231723
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
17241724
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==
17251725

1726-
1727-
version "2.3.2"
1728-
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
1729-
integrity sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==
1730-
17311726
"@types/webpack-env@^1.15.1":
17321727
version "1.16.0"
17331728
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.0.tgz#8c0a9435dfa7b3b1be76562f3070efb3f92637b4"
@@ -4540,11 +4535,6 @@ event-stream@=3.3.4:
45404535
stream-combiner "~0.0.4"
45414536
through "~2.3.1"
45424537

4543-
4544-
version "4.1.2"
4545-
resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-4.1.2.tgz#0e1a8477af821a6ef3995b311bf74c23a5247f15"
4546-
integrity sha1-DhqEd6+CGm7zmVsxG/dMI6UkfxU=
4547-
45484538
eventemitter3@^3.1.0:
45494539
version "3.1.2"
45504540
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"
@@ -9999,11 +9989,6 @@ [email protected], unpipe@~1.0.0:
99999989
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
100009990
integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=
100019991

10002-
10003-
version "3.0.3"
10004-
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.3.tgz#1e7b42b140bcfd922b22e70ca1265bfe3634c7c9"
10005-
integrity sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA==
10006-
100079992
upath@^2.0.1:
100089993
version "2.0.1"
100099994
resolved "https://registry.yarnpkg.com/upath/-/upath-2.0.1.tgz#50c73dea68d6f6b990f51d279ce6081665d61a8b"
@@ -10260,6 +10245,13 @@ vuex@^3.4.0:
1026010245
resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.6.2.tgz#236bc086a870c3ae79946f107f16de59d5895e71"
1026110246
integrity sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw==
1026210247

10248+
vuex@^4.0.1:
10249+
version "4.0.1"
10250+
resolved "https://registry.yarnpkg.com/vuex/-/vuex-4.0.1.tgz#e83c541d6f31173969efabb2c5d1c465b682887e"
10251+
integrity sha512-MddakQTAnImDkK1YhEESowKSU5KcjqHH3L1ScPx1lj6NzDDX0FuRBZqJoME5O7/nvj9puudDf6xnWU2w/cqI7g==
10252+
dependencies:
10253+
"@vue/devtools-api" "^6.0.0-beta.11"
10254+
1026310255
1026410256
version "5.3.0"
1026510257
resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-5.3.0.tgz#584e17d4b3fe7b46ac2b9f8e5e102c005c2776c7"

0 commit comments

Comments
 (0)