import * as types from '../types'
//数据
const state = {
travelsList: [],
searchKey: {
page: 0,
limit: 20
},
scroll: true
}
//用户行为(可以处理异步),触发 mutations 来改变 state
const actions = {
/**
* 获取约跑步列表
*/
getTravelsList({ commit }) {
if(state.scroll) {
commit(types.GET_TRAVELS_PAGE_NUM)
commit(types.COM_LOADING_STATUS, true),
commit(types.GET_TRAVELS_SCORLL_STATUS, false)
api.TravelsList()
.then(res => {
console.log(res)
commit(types.COM_LOADING_STATUS, false),
commit(types.GET_TRAVELS_SCORLL_STATUS, true)
commit(types.GET_TRAVELS_LIST, res)
})
}
},
/**
* 参加
*/
joinTravel({ commit }, id) {
...
}
}
//可以过滤 state 中的数据
const getters = {
travelsList: state => state.travelsList,
travelListIndex: state => state.travelsList.slice(0,4)
}
//唯一能改变 state 的方法(纯函数)
const mutations = {
[types.GET_TRAVELS_LIST](state, res) {
if(state.searchKey.page <= 1) {
state.travelsList = res.data
} else {
state.travelsList = state.travelsList.concat(res.data)
}
},
[types.GET_TRAVELS_SEARCH_KEY](state, params) {
state.searchKey = params
},
[types.GET_TRAVELS_PAGE_NUM](state) {
state.searchKey['page'] += 1
},
[types.GET_TRAVELS_SCORLL_STATUS](state, status) {
state.scroll = status
}
}
//导出一个 travel store 模块
export default {
state,
actions,
getters,
mutations
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有