import axios from 'axios'
export const state = () => ({
products: []
})
export const mutations = {
SET_PRODUCTS_TO_STATE: (state,products) => {
state.products = products;
}
}
export const actions = {
GET_PRODUCTS_FROM_API({commit}) {
return axios('https://jsonplaceholder.typicode.com/todos/1',{
method: "GET"
})
.then((products) => {
comit('SET_PRODUCTS_TO_STATE', products);
return products;
})
.catch((error) => {
console.log(error)
return error;
})
}
}
export const getters = {
PRODUCTS(state) {
return state.products
}
}