Showing
3 changed files
with
49 additions
and
9 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') |
| 30 | }, | 36 | }, |
| 31 | - decrement () { | 37 | + decrement() { |
| 32 | store.commit('decrement') | 38 | store.commit('decrement') |
| 33 | } | 39 | } |
| 34 | }, | 40 | }, |
| 35 | components: { | 41 | components: { |
| 36 | - counter | 42 | + counter,child |
| 37 | } | 43 | } |
| 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> |
-
Please register or login to post a comment