npm install @nuxtjs/axios
import {ACTIVE_COUNTRY_ID, CITY, COUNTRIES, CATEGORIES, REGION, TITLE, COUNTRY} from "./mutation-types";
export const state = () => ({
[TITLE]: "",
[CITY]: {
id: 0,
name: ""
},
[REGION]: {
id: 0,
name: ""
},
[ACTIVE_COUNTRY_ID]: 0,
[COUNTRY]: {
id: 0,
name: ""
},
[COUNTRIES]: [],
[CATEGORIES]: [],
});
response
следует передавать response.data
mutations: {
setTodos: (state, todos) => state.todos = todos,
},
actions: {
async getTodos({ commit }) {
const results = [];
for (let i = 1; i <= 10; i++) {
try {
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/todos/${i}`);
results.push(data);
} catch (e) {
console.log(e);
}
}
commit('setTodos', results);
},
},
<ul>
<li v-for="n in $store.state.todos" :key="n.id">
<div>#{{ n.id }}</div>
<div>{{ n.title }}</div>
</li>
</ul>