使用的时候 主要包 try catch
try {
this.$store.commit('addNewProject',{projectName:
this.addProjcetFrom.projectName,projectType: this.addProjcetFrom.projectType})
this.$store.commit('setCurrentProjcetIndex',{index:this.$store.state.project.list.length - 1})
this.closeProjectModel()
}catch (e) {
this.$notify.error({
title: '错误',
message: e.msg
});
}
在vuex里面抛出错误
addNewProject(state,{projectName,projectType}){
state.list.forEach(e=>{
if (projectName === e.projectName) {
throw {msg: '已存在同名项目名!'}
//主要这一步 throw 抛出,外面就能接收到
}
})
state.list.push({
projectName: projectName,
projectType: projectType,
listData: JSON.parse(JSON.stringify(projectDefaultData))
})
cachesFolder(state.list)
},