Last active
October 16, 2017 11:23
-
-
Save ajiehatajie/ab4bd5a88df2853414a43b6bc8284380 to your computer and use it in GitHub Desktop.
nuxtjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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