Browse Source

优化逻辑,全局注入vuex getters

master
zmt 3 years ago
parent
commit
78a4d77d9b
  1. 6
      nxTemp/store/index.js
  2. 2
      pages.json
  3. 34
      pages/index/index.vue
  4. 6
      pages/message/center_list.vue

6
nxTemp/store/index.js

@ -6,13 +6,15 @@ const files = require.context("./modules", false, /\.js$/);
let modules = {
state: {},
mutations: {},
actions: {}
actions: {},
getters:{}
};
files.keys().forEach((key) => {
Object.assign(modules.state, files(key)["state"]);
Object.assign(modules.mutations, files(key)["mutations"]);
Object.assign(modules.actions, files(key)["actions"]);
Object.assign(modules.actions, files(key)["actions"]);
Object.assign(modules.getters, files(key)["getters"]);
});
const store = new Vuex.Store(modules);
export default store;

2
pages.json

@ -124,7 +124,7 @@
"list": [
{
"name": "登录页面", //
"path": "pages/login/login", //
"path": "pages/index/index", //
"query": "" //onLoad
}
]

34
pages/index/index.vue

@ -18,9 +18,9 @@
<image src="../../static/images/index/arrow_right.png" mode=""></image>
</view>
<view class="item flex_row flex_start bg-white padding solid-bottom" @click="jumpPage('eventList')">
<view class="item flex_row flex_start bg-white padding solid-bottom" @click="clickEvent">
<image src="../../static/images/index/index_cup.png" mode=""></image>
<view class="text-m text-left">活动赛事</view>
<view class="text-m text-left">活动赛事{{hasLogin}}+{{userInfo.mobile}}</view>
<image src="../../static/images/index/arrow_right.png" mode=""></image>
</view>
@ -32,19 +32,20 @@
</view>
</template>
<script>
import { mapState } from 'vuex'
import { mapState,mapActions,mapGetters } from 'vuex'
export default {
data() {
return {
address:"",
login:true
login:false
};
},
computed:{
...mapState(['userInfo']),
getUserInfo(){
return this.$store.state.userInfo.mobile
}
...mapGetters(['hasLogin']),
// hasLogin(){
// return this.$store.getters.hasLogin
// }
},
onLoad(parms) {
@ -52,10 +53,27 @@
onUnload() {
},
methods: {
methods: {
...mapActions(['getUserInfo']),
jumpPage(name){
this.$Router.push({name:name})
// this.$Router.pushTab('/pages/login/login')
},
clickEvent(){
let that = this
if(this.login)this.jumpPage('eventList');
else {
uni.showModal({
title: '提示',
content: '需要登录后才能查看,是否跳转去登录界面?',
success: function (res) {
if (res.confirm) {
that.jumpPage('login');
} else if (res.cancel) {
}
}
});
}
},
}
}

6
pages/message/center_list.vue

@ -2,7 +2,7 @@
<view class="content flex_col flex_start">
<!-- item -->
<view class="item flex_col flex_start_y bg-white padding " v-for="i in 3">
<view class="item flex_col flex_start_y bg-white padding " v-for="i in 3" @click="jumpPage('messageDetail')">
<view class="title flex_row flex_start">
<view class="text-m text-left">消息中心</view>
<view class="bandage"></view>
@ -28,8 +28,8 @@
},
methods: {
jumpPage(){
this.$Router.push({name:"login"})
jumpPage(name){
this.$Router.push({name:name})
},
}
}

Loading…
Cancel
Save