- <template>
- <div id="app">
-
- {{count}}
- {{name}}
- </div>
- </template>
- <script>
- import { mapState } from 'vuex';
- //第二种方法 返回多个vuex里面数据 采用es6 ...的方法取值
- const obj=mapState(['count','name'])
- export default {
- data () {
- return {
-
- }
- },
-
- computed: {
- ...obj
- }
- //第一种方法 返回单个vuex 当中state里面数据
- // computed: {
- // count(){
- // return this.$store.state.count
- // }
- // }
-
- }
- </script>
- <style>
-
- </style>
- import Vue from 'vue'
- import Vuex from 'vuex'
-
- Vue.use(Vuex)
-
- export default new Vuex.Store({
- state: {
- count:0,
- name:'zhangsan'
- },
- getters: {
- },
- mutations: {
- },
- actions: {
- },
- modules: {
- }
- })
- import Vue from 'vue'
- import App from './App.vue'
- import router from './router'
- import store from './store'
-
- //在main.js里面引用
- import axios from 'axios'
- Vue.prototype.axios = axios;
-
- Vue.config.productionTip = false
-
- new Vue({
- axios,
- router,
- store,
- render: h => h(App)
- }).$mount('#app')