vuex在module中定义了state和mutaition,
请问一下大家,我如何在组件中修改这个state.
因为这个state获取的是返回的日期,在组件中我希望用moment插件,this.$moment("这个日期")来进行格式化,在显示在页面中,看了很就文档,当时还是没明白改怎么修改呀?
下面是module是的代码:
import axios from 'axios'
axios.defaults.baseURL = 'xxxxxxx';
const state = {
title:"",
authorName:"",
pubNews:"",
channelNews:"",
createAt:"",
content:""
};
const mutations = {
GETDETAILS(state,res){
state.title=res.data.news.title;
state.authorName=res.data.news.authorName;
state.pubNews=res.data.news.pubNews;
state.channelNews=res.data.news.channelNews;
state.createAt=res.data.news.createAt;
state.content=res.data.news.content;
}
};
const actions = {
getDetails({commit},id){
axios.get("/news/detail",{withCredentials:true,params:{id:id}}).then(res=>{
commit("GETDETAILS",res)
})
}
};
export default{
state,
mutations,
actions
}
createAt是那个创建日期,我想要在组件中格式化这个日期
POPMUISE
慕仙森