newsData.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. console.log(params.id)
  16. let id = params.id
  17. commit('detailNews/REQUEST_DETAILNEWS', params)
  18. return axios.get(`/api/news/${id}`)
  19. .then(response => {
  20. commit('detailNews/GET_DETAILNEWS_SUCCESS', response.data)
  21. }, err => {
  22. commit('detailNews/GET_DETAILNEWS_FAILURE', err)
  23. })
  24. },
  25. // 获取热点新闻
  26. loadHotNews ({ commit }, params = {}) {
  27. commit('hotNews/REQUEST_HOTNEWS')
  28. return axios.get('/api/news/viewCount', {params})
  29. .then(response => {
  30. commit('hotNews/GET_HOTNEWS_SUCCESS', response.data)
  31. }, err => {
  32. commit('hotNews/GET_HOTNEWS_FAILURE', err)
  33. })
  34. }
  35. }