Postingan lainnya
Buku Ini Koding!
Baru!
Buku ini akan jadi teman perjalanan kamu belajar sampai dapat kerjaan di dunia programming!
Cara menggunakan async nuxtserverinit di store
Saya telah mengikuti tutorial memindahkan data di vuex store, tetapi async nuxtServerInit tidak berfungsi, mohon di koreksi bila salah
ini file index.js di store
import axios from '~/plugins/axios'
export const state = () => ({
customer:[]
})
export const mutations = {
setCustomer(state, items){
state.customer = items
}
}
export const actions = {
async nuxtServerInit( {commit} ){
console.log("troololollo")
const { data } = await axios.get('all_customer')
commit('setCustomer',data.data)
}
}
ini file index.vue
<script>
import { mapState } from 'vuex'
export default{
computed: mapState([
'customer'
])
}
</script>
0
1 Jawaban:
Permisi gan, coba restart dulu servernya npm run dev lagi. Soalnya saya juga pernah mengalami error yg seperti ini, tapi setelah saya stop servernya dan npm run dev lagi baru bisa jalan codenya.
Semoga work gan
0