Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
demo-vue-vuex
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Hooke
2016-10-29 22:00:22 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
71da455f00bbb866ba8671d236d00baec31c48fb
71da455f
1 parent
31e18954
vuex 中全局共享登录状态
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
9 deletions
src/App.vue
src/components/myParagraph.vue
src/main.js
src/App.vue
View file @
71da455
<template>
<div id="app">
<counter></counter>
<div class="">
{{isLogin}}
</div>
<p>
<button @click="increment">+</button>
<button @click="decrement">-</button>
<button @click="login">login</button>
</p>
<child :level="1">Hello world!</child>
<child :level="3">Hello world!</child>
...
...
@@ -28,6 +32,9 @@ export default {
computed: {
count() {
return store.state.count
},
isLogin() {
return store.state.isLogin
}
},
methods: {
...
...
@@ -36,6 +43,9 @@ export default {
},
decrement() {
store.commit('decrement')
},
login() {
store.commit('login')
}
},
components: {
...
...
src/components/myParagraph.vue
View file @
71da455
...
...
@@ -13,13 +13,13 @@ export default {
// // Yikes - duplicate VNodes!
// myParagraphVNode, myParagraphVNode
// ])
return createElement('div',
Array.apply(null, {
length: 10
}).map(function() {
return createElement('p', 'hi')
})
)
//
return createElement('div',
//
Array.apply(null, {
//
length: 10
//
}).map(function() {
//
return createElement('p', 'hi')
//
})
//
)
}
}
</script>
...
...
src/main.js
View file @
71da455
...
...
@@ -6,11 +6,14 @@ Vue.use(Vuex)
const
store
=
new
Vuex
.
Store
({
state
:
{
count
:
0
count
:
0
,
size
:
10
,
isLogin
:
false
},
mutations
:
{
increment
:
state
=>
state
.
count
++
,
decrement
:
state
=>
state
.
count
--
decrement
:
state
=>
state
.
count
--
,
login
:
state
=>
state
.
isLogin
=
true
}
})
...
...
Please
register
or
login
to post a comment