Skip to content

Instantly share code, notes, and snippets.

@ajiehatajie
Last active October 16, 2017 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajiehatajie/ab4bd5a88df2853414a43b6bc8284380 to your computer and use it in GitHub Desktop.
Save ajiehatajie/ab4bd5a88df2853414a43b6bc8284380 to your computer and use it in GitHub Desktop.
nuxtjs
store/index.js
const GET_DATA = 'GET_DATA'
const API_ERROR = 'API_ERROR'
const API_URL = 'http://hatajieblog.dev/api/v1/'
export const state = () => ({
posts: []
})
export const actions = {
async getPost ({ commit }) {
const ip = await this.$axios.$get('http://hatajieblog.dev/api/v1/post')
commit('GET_DATA', ip.data)
console.log(ip.data)
return ip.data;
}
}
export const getters = {
posts : state => {
return state.posts
}
}
export const mutations = {
[GET_DATA](state,payload){
state.posts = payload
console.log(payload)
},
[API_ERROR](state,payload){
console.log(payload)
}
}
//component/post.vue
<template>
<div>
POST
ini adalah post
<h1>Stars: {{ $store.state.posts }}</h1>
</div>
</template>
<script>
import { mapGetters,mapActions } from 'vuex'
export default {
props: ['posts'],
computed: {
...mapActions ([
'getPost'
])
},
methods : {
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment