blog.js 992 B

12345678910111213141516171819202122232425262728293031323334
  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. }
  28. export const mutations = {
  29. setBlog(state, blog) {
  30. state.item = blog
  31. }
  32. }