从过帐请求中获取数据后,我需要按部门(市场,开发,HR和Ui / UX)过滤它们,以将其显示在相应的部门清单上。但是我的数据过滤器正在累积。例如,当我单击营销链接时,它会添加该部门的帖子,但是如果我切换到人力资源,则会添加hr帖子和营销帖子。
我试图通过推送从get请求接收的帖子来改变状态,并在推送之前清空数组
async getArticles({commit}, depart){
Axios.defaults.headers.common['Authorization'] = 'Bearer ' + this.state.token;
try{
const response = await Axios.get('http://localhost:3000/api/articles');
const articles = await response.data;
articles.forEach(article => {
if(article.department.includes(depart)){
commit('setArticles', article);
}
});
}catch(error){
console.log(error);
}
},
setArticles(state, articles){
state.articles.push(articles);
}
articles : [],
computed : {
...mapState([
'articles'
])
},
mounted() {
this.$store.dispatch('getArticles', "Marketing");
},
我希望能够按部门获取职位。