blog.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. export const state = () => ({
  2. item: {}
  3. })
  4. export const actions = {
  5. async createBlog(_, blogData) {
  6. try {
  7. console.log('instructor/blog.js actions createBlog call axios.$post->blogData')
  8. const blog = await this.$axios.$post('/api/v1/blogs', blogData)
  9. console.log('instructor/blog.js actions createBlog done axios.$post->blogData')
  10. return blog
  11. } catch (error) {
  12. return error
  13. }
  14. },
  15. async fetchBlogById({commit}, blogId) {
  16. try {
  17. console.log('instructor/blog.js actions fetchBlogById call axios.$get->blogId')
  18. const blog = await this.$axios.$get(`/api/v1/blogs/${blogId}`)
  19. console.log('instructor/blog.js actions fetchBlogById done axios.$get->blogId')
  20. console.log('courses.js mutations call setBlog')
  21. commit('setBlog', blog)
  22. console.log('courses.js mutations done setBlog')
  23. } catch (error) {
  24. return error
  25. }
  26. },
  27. async updateBlog({commit, state}, {data, id}) {
  28. try {
  29. console.log('instructor/blog.js actions updateBlog call axios.$patch-> Id, data')
  30. const blog = await this.$axios.$patch(`/api/v1/blogs/${id}`, data)
  31. console.log('instructor/blog.js actions updateBlog done axios.$patch-> Id, data')
  32. console.log('courses.js mutations call setBlog')
  33. commit('setBlog', blog)
  34. console.log('courses.js mutations done setBlog')
  35. return state.item
  36. } catch (error) {
  37. return error
  38. }
  39. }
  40. }
  41. export const mutations = {
  42. setBlog(state, blog) {
  43. state.item = blog
  44. }
  45. }