-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6538247
commit f23edd2
Showing
6 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
import Comments from '../../containers/Comments'; | ||
import store from '../../store'; | ||
import * as types from '../../store/mutation-types'; | ||
import { | ||
comments, | ||
} from '../server'; | ||
|
||
export default { | ||
path: '/comments/:currentMovieId', | ||
component: Comments, | ||
beforeEnter: (to, before, next) => { | ||
document.title = '短评 - 电影 - 豆瓣'; | ||
store.commit(types.LOADING_FLAG, false); | ||
const currentMovieId = to.params.currentMovieId; | ||
if (store.state.comments.currentComments[`${currentMovieId}`]) { | ||
store.commit(types.LOADING_FLAG, false); | ||
next(); | ||
return; | ||
} | ||
store.commit(types.LOADING_FLAG, true); | ||
comments(currentMovieId, 20, 0).then((currentCommentsDetail) => { | ||
// 成功则commit后台接口的数据,并把NET_ERROR的数据置空,并把加载中的状态置为false。 | ||
const id = currentCommentsDetail.subject.id; | ||
store.commit(types.CURRENT_COMMENTS, { | ||
[`${id}`]: currentCommentsDetail, | ||
...store.state.comments.currentComments, | ||
}); | ||
store.commit(types.LOADING_FLAG, false); | ||
store.commit(types.NET_STATUS, ''); | ||
document.title = `全部短评 - 电影:${currentCommentsDetail.subject.title} - 豆瓣`; | ||
}).catch((error) => { | ||
document.title = '出错啦 Oops… - 豆瓣'; | ||
store.commit(types.NET_STATUS, error); | ||
store.commit(types.LOADING_FLAG, false); | ||
}); | ||
next(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as types from '../mutation-types'; | ||
|
||
const state = { | ||
currentComments: {}, | ||
}; | ||
|
||
const getters = {}; | ||
|
||
const actions = {}; | ||
|
||
const mutations = { | ||
[types.CURRENT_COMMENTS](state, currentComments) { | ||
state.currentComments = currentComments; | ||
}, | ||
}; | ||
|
||
export default { | ||
state, | ||
getters, | ||
actions, | ||
mutations, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters