4가지 방법이 존재하는데,
this.$store.state.user
속성 바인딩(html tag가 지저분해 짐)this.$store.state.user
2번 방법이 제일 깔끔한듯
<template>
<div>
<p>name : {{userInfo.id}}</p>
<p>karma : {{userInfo.karma}}</p>
<p>created : {{userInfo.created}}</p>
</div>
</template>
<script>
export default {
computed : {
userInfo(){
return this.$store.state.user;
}
},
</script>
만약 mapState를 쓴다면...
<script>
import { mapState } from 'vuex'; //지저분해
export default {
computed:{
...mapState({ //지저분하고 명확하다는 느낌이 안 듬
news : state => state.news
})
},
created() {
this.$store.dispatch('FETCH_NEWS');
},
};
</script>