I am new to Nuxt JS and following a tutorial on the Nuxt website. I created a store in store/index.js.
export const state = () => ({
mountain: [],
})
export const mutations = {
addMountain(state, mountain) {
state.mountain.push(mountain)
},
}
export const actions = {
async fetchMountain() {
const mountain = await fetch("https://api.nuxtjs.dev/mountains").then(
(res) => res.json()
);
// this.mountain = mountain
}
}
After that, I created a page in pages/index.js.
<template>
<div>
<h1>Nuxt Mountains</h1>
<ul>
<li v-for="mount of mountain">{{ mount.title }}</li>
</ul>
<button @click="$fetch">Refresh</button>
</div>
</template>
<script>
import $store from "~/store";
export default {
fetch() {
return $store.state.mountain;
},
};
</script>
However, when I run the page, I don't see anything displayed. Can someone help me with this issue?