.vue
export default {
data(){
return{
// useID:api.hdCookie.getCookie('userID')
}
},
computed:{
proList(){
return this.$store.getters.getPageList
},
useID(){
return api.hdCookie.getCookie('userID')
},
page(){
return 1
},
num(){
return 8
}
},
mounted(){
this.$store.dispatch('fetchPageList');
console.log(this.$store);
},
methods:{
}
}
store
import Vue from 'vue'
const state = {
pageList: [],
pageIndex: undefined,
pageNum: 10
}
const getters = {
getPageList: state => state.pageList,
getPageIndex: state => state.pageIndex,
getPageNum: state => state.pageNum
}
const actions = {
fetchPageList({ commit, state }) {
Vue.http.get('https://xxx?userId=' + useID + '&pageIndex=' + page + '&pageNum=' + '10')
.then((res) => {
commit('changePageList', JSON.parse(res.data.content).projectList)
}, (err) => {
})
}
}
const mutations = {
changePageList(state, payload) {
state.pageList = payload
},
updateParams(state, { key, val }) {
state.params[key] = val
}
}
export default {
state,
getters,
actions,
mutations
}
如上,.vue组件需要向store里面传值,需要把useID,page,num传进来,动态修改http url的参数值?
this.$store.dispatch('incrementAsync', {
useID: 10,
page: 1
})
const actions = {
fetchPageList({ commit, state }, data) {
let {useID, page} = data
Vue.http.get('https://xxx?userId=' + useID + '&pageIndex=' + page + '&pageNum=' + '10')
.then((res) => {
commit('changePageList', JSON.parse(res.data.content).projectList)
}, (err) => {
})
}
}