Showing
3 changed files
with
75 additions
and
35 deletions
| 1 | <template> | 1 | <template> |
| 2 | - <div id="app"> | 2 | +<div id="app"> |
| 3 | <counter></counter> | 3 | <counter></counter> |
| 4 | <p> | 4 | <p> |
| 5 | - <button @click="increment">+</button> | 5 | + <button @click="increment">+</button> |
| 6 | - <button @click="decrement">-</button> | 6 | + <button @click="decrement">-</button> |
| 7 | </p> | 7 | </p> |
| 8 | - </div> | 8 | + <child :level="1">Hello world!</child> |
| 9 | + <child :level="3">Hello world!</child> | ||
| 10 | +</div> | ||
| 9 | </template> | 11 | </template> |
| 10 | 12 | ||
| 11 | <script> | 13 | <script> |
| 12 | import counter from './components/counter.vue' | 14 | import counter from './components/counter.vue' |
| 13 | -import {store} from './main.js' | 15 | +import child from './components/child.vue' |
| 16 | + | ||
| 17 | +import { | ||
| 18 | + store | ||
| 19 | +} from './main.js' | ||
| 14 | 20 | ||
| 15 | export default { | 21 | export default { |
| 16 | - name: 'app', | 22 | + name: 'app', |
| 17 | - data () { | 23 | + data() { |
| 18 | - return { | 24 | + return { |
| 19 | 25 | ||
| 20 | - } | 26 | + } |
| 21 | - }, | 27 | + }, |
| 22 | - computed: { | 28 | + computed: { |
| 23 | - count () { | 29 | + count() { |
| 24 | - return store.state.count | 30 | + return store.state.count |
| 25 | - } | 31 | + } |
| 26 | - }, | 32 | + }, |
| 27 | - methods: { | 33 | + methods: { |
| 28 | - increment () { | 34 | + increment() { |
| 29 | - store.commit('increment') | 35 | + store.commit('increment') |
| 36 | + }, | ||
| 37 | + decrement() { | ||
| 38 | + store.commit('decrement') | ||
| 39 | + } | ||
| 30 | }, | 40 | }, |
| 31 | - decrement () { | 41 | + components: { |
| 32 | - store.commit('decrement') | 42 | + counter,child |
| 33 | } | 43 | } |
| 34 | - }, | ||
| 35 | - components: { | ||
| 36 | - counter | ||
| 37 | - } | ||
| 38 | } | 44 | } |
| 39 | </script> | 45 | </script> | ... | ... |
src/components/child.vue
0 → 100644
| 1 | +<script> | ||
| 2 | +export default { | ||
| 3 | + data() { | ||
| 4 | + return { | ||
| 5 | + | ||
| 6 | + } | ||
| 7 | + }, | ||
| 8 | + computed: { | ||
| 9 | + | ||
| 10 | + }, | ||
| 11 | + mounted() { | ||
| 12 | + | ||
| 13 | + }, | ||
| 14 | + methods: {}, | ||
| 15 | + components: {}, | ||
| 16 | + render: function(createElement) { | ||
| 17 | + return createElement( | ||
| 18 | + 'h' + this.level, | ||
| 19 | + this.$slots.default | ||
| 20 | + ) | ||
| 21 | + }, | ||
| 22 | + props: { | ||
| 23 | + level: { | ||
| 24 | + type: Number, | ||
| 25 | + required: true | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | +</script> | ||
| 30 | + | ||
| 31 | +<style lang="css"> | ||
| 32 | +</style> |
| ... | @@ -5,19 +5,21 @@ import App from './App.vue' | ... | @@ -5,19 +5,21 @@ import App from './App.vue' |
| 5 | Vue.use(Vuex) | 5 | Vue.use(Vuex) |
| 6 | 6 | ||
| 7 | const store = new Vuex.Store({ | 7 | const store = new Vuex.Store({ |
| 8 | - state: { | 8 | + state: { |
| 9 | - count: 0 | 9 | + count: 0 |
| 10 | - }, | 10 | + }, |
| 11 | - mutations: { | 11 | + mutations: { |
| 12 | - increment: state => state.count++, | 12 | + increment: state => state.count++, |
| 13 | - decrement: state => state.count-- | 13 | + decrement: state => state.count-- |
| 14 | - } | 14 | + } |
| 15 | }) | 15 | }) |
| 16 | 16 | ||
| 17 | new Vue({ | 17 | new Vue({ |
| 18 | - el: '#app', | 18 | + el: '#app', |
| 19 | - store, | 19 | + store, |
| 20 | - render: h => h(App) | 20 | + render: h => h(App) |
| 21 | }) | 21 | }) |
| 22 | 22 | ||
| 23 | -export { store } | 23 | +export { |
| 24 | + store | ||
| 25 | +} | ... | ... |
-
Please register or login to post a comment