서버에서 크롤링한 데이터를 vue에 전달하는 코드 짰는데 제 폰으로 확인해보니 axios 혹은 vuex 부분이 동작하지 않는 것 같습니다.
pc 크롬으로 확인했을 때는 문제없이 출력됐는데 모바일 크롬으로 보면 데이터 출력해주는 부분이 비어서 나오네요.
아래 코드가 서버에서 데이터 받는 부분인데 어디가 잘못된걸까요...? 출력은 같은 뷰 컴포넌트(Card.vue)에서 해주려고 합니다.
(Card.vue 스크립트 부분)
<script>
export default {
name: 'Card',
beforeCreate() {
this.$store.dispatch('getNovels');
},
}
</script>
(store.js)
import axios from 'axios';
import { createStore } from 'vuex'
const store = createStore({
state(){
return {
novels : [],
checker : null,
}
},
mutations : {
setNovels(state, payload) {
state.novels = [...payload.data];
},
chk(state) {
// console.log(state.novels);
state.checker = state.novels[1];
}
},
actions : {
getNovels(context) {
axios.get('http://localhost:3000/search')
.then((result) => {
context.commit('setNovels', result);
}).catch((err) => {
console.log(err);
})
}
}
})
export default store