[img][/img]
1 | cnpm install vuex -S |
1 2 3 4 5 6 7 8 9 10 11 12 13 | import Vue from 'vue' import App from './App' import Vuex from 'vuex' import store from './vuex/store' Vue.use(Vuex) /* eslint-disable no-new */ new Vue({ el: '#app', store, render: h => h(App) }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 | import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ // 定义状态 state: { author: 'Wise Wrong' } }) export default store |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <template> <footer class="footer"> <ul> <li v-for="lis in ul">{{lis.li}}</li> </ul> <p> Copyright © {{author}} - 2016 All rights reserved </p> </footer> </template> <script> export default { name: 'footerDiv', data () { return { ul: [ { li: '琉璃之金' }, { li: '朦胧之森' }, { li: '缥缈之滔' }, { li: '逍遥之火' }, { li: '璀璨之沙' } ] } }, computed: { author () { return this.$store.state.author } } } </script> |
[img][/img]
[img][/img]
1 2 3 4 5 | methods: { setAuthor: function () { this.$store.state.author = this.inpuTxt } } |
[img][/img]
[img][/img]
[img][/img]
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |