1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- export const state = () => ({
- items : [],
- item : []
- })
- export const actions = {
- async fetchInstructorCourses({commit}) {
- try{
- console.log('courses.js actions call fetchInstructorCourses')
- const courses = await this.$axios.$get('/api/v1/products/user-products')
- console.log('courses.js actions done fetchInstructorCourses')
- console.log('courses.js mutations call setCourses')
- commit('setCourses', courses)
- console.log('courses.js mutations done setCourses')
- return courses
- }catch(error){
- return error
- }
- },
- async createCourse(_, courseData) {
- try {
- console.log('instructor/course.js actions createCourse call axios.$post->products')
- const result = await this.$axios.$post('/api/v1/products', courseData)
- console.log('instructor/course.js actions createCourse done axios.$post->products')
- } catch (error) {
- return error
- }
- },
- async fetchCourseById({commit, state}, courseId){
- try {
- console.log('instructor/course.js actions fetchCourseById call axios.$get->courseId')
- const course = await this.$axios.$get(`/api/v1/products/${courseId}`)
- console.log('instructor/course.js actions fetchCourseById done axios.$get->courseId')
- console.log('courses.js mutations call setCourse')
- commit('setCourse', course)
- console.log('courses.js mutations done setCourse')
- return state.item
- } catch (error) {
- return error
- }
- },
- }
- export const mutations = {
- setCourses(state, courses) {
- state.items = courses
- },
- setCourse(state, course) {
- state.item = course
- },
- addLine(state, field) {
- console.log('course.js mutations call addLine params > ', field)
- state.item[field].push({value: ''})
- console.log('course.js mutations done addLine params')
- },
- removeLine(state, {field, index}) {
- console.log('course.js mutations call removeLine params > ', field, ':', index)
- state.item[field].splice(index, 1)
- console.log('course.js mutations done removeLine params')
- }
- }
|