newsData.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import axios from '~plugins/axios'
  2. export const actions = {
  3. // 获取快讯页新闻
  4. loadAllNews ({ commit }, params = {}) {
  5. commit('newsPage/REQUEST_ALLNEWS')
  6. return axios.get('/api/news/created', {params})
  7. .then(response => {
  8. commit('newsPage/GET_ALLNEWS_SUCCESS', response.data)
  9. }, err => {
  10. commit('newsPage/GET_ALLNEWS_FAILURE', err)
  11. })
  12. },
  13. // 获取详细新闻
  14. loadDetailNews ({ commit }, params = {}) {
  15. let id = params.id
  16. commit('detailNews/REQUEST_DETAILNEWS', params)
  17. return axios.get(`/api/news/${id}`)
  18. .then(response => {
  19. commit('detailNews/GET_DETAILNEWS_SUCCESS', response.data)
  20. }, err => {
  21. commit('detailNews/GET_DETAILNEWS_FAILURE', err)
  22. })
  23. },
  24. // 获取热点新闻
  25. loadHotNews ({ commit }, params = {}) {
  26. commit('hotNews/REQUEST_HOTNEWS')
  27. return axios.get('/api/news/viewCount', {params})
  28. .then(response => {
  29. commit('hotNews/GET_HOTNEWS_SUCCESS', response.data)
  30. }, err => {
  31. commit('hotNews/GET_HOTNEWS_FAILURE', err)
  32. })
  33. }
  34. }