From 91241682ded2603113b7d100636b6177bcf01c9a Mon Sep 17 00:00:00 2001
From: ghusermoon <2673031505@qq.com>
Date: Wed, 15 Jul 2020 17:38:41 +0800
Subject: [PATCH] 7.15
---
common/store/index.js | 57 ++++++++++++++-----------------------------
main.js | 8 +++---
pages/shop/index.vue | 5 ++--
3 files changed, 24 insertions(+), 46 deletions(-)
diff --git a/common/store/index.js b/common/store/index.js
index b80b0a4..5dd2d35 100644
--- a/common/store/index.js
+++ b/common/store/index.js
@@ -1,41 +1,20 @@
-// 商品相关
-const moduleA = {
- state: () => ({
- count: 0
- }),
- mutations: {
- increment (state) {
- // 这里的 `state` 对象是模块的局部状态
- state.count++
- }
- },
- getters: {
- doubleCount (state) {
- return state.count * 2
- }
- }
-}
-// 用户相关
-const moduleB = {
- state: () => ({
- count: 0
- }),
- mutations: {
- increment (state) {
- // 这里的 `state` 对象是模块的局部状态
- state.count++
- }
- },
- getters: {
- doubleCount (state) {
- return state.count * 2
- }
- }
-}
-
+import Vue from 'vue'
+import Vuex from 'vuex'
+Vue.use(Vuex)
+
const store = new Vuex.Store({
- modules: {
- shop: moduleA,
- user: moduleB
+ state: {
+ count: 0
+ },
+ getters: {
+ doubleCount (state) {
+ return state.count * 2
+ }
+ },
+ mutations: {
+ increment (state) {
+ state.count++
+ }
}
-})
\ No newline at end of file
+})
+export default store;
\ No newline at end of file
diff --git a/main.js b/main.js
index 3312df3..b0acc13 100644
--- a/main.js
+++ b/main.js
@@ -1,17 +1,17 @@
import Vue from 'vue'
import App from './App'
import uView from "uview-ui";
-// import Vuex from 'vuex'
Vue.config.productionTip = false
Vue.use(uView);
-// Vue.use(Vuex);
App.mpType = 'app'
-// import store from '@/common/store/index.js'
+import store from '@/common/store/index.js'
+
+Vue.prototype.$store = store;
const app = new Vue({
...App,
- // store
+ store
})
// http拦截器,将此部分放在new Vue()和app.$mount()之间,才能App.vue中正常使用
import httpInterceptor from '@/common/http.interceptor.js'
diff --git a/pages/shop/index.vue b/pages/shop/index.vue
index 915e9cc..03e785d 100644
--- a/pages/shop/index.vue
+++ b/pages/shop/index.vue
@@ -41,8 +41,8 @@
-
-
+
+
@@ -95,7 +95,6 @@ export default {
this.getGoodsRecommend();
},
onShow() {
- // console.log(this.$store.shop.state.count);
this.getRecommendedSpike();
this.getSpikeList();
},