inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Vue로 Nodebird SNS 만들기

이미지 불러올때 질문있습니다

189

fitstj123

작성한 질문수 5

0

항상 좋은 강의 감사드립니다 현재 강의를듣다가 문제가 발생하여 질문드립니다.

5-4이미지 저장하기 부분을 진행중이고 현재 저의상화은 로그인 후 글,이미지가 성공적으로 데이터베이스에 저장되고 글목록에 이미지와 쓴글이 뜹니다.

문제는 이미지를 불러올때 에러가 발생합니다. (그냥 글만쓸때는 해당 에러가 발생하지 않습니다)

이미지를 두개이상 업로드시 아래 에러가 발생합니다.

화면상으로는 문제가 없습니다만 아래 에러가 발생합니다.

이런식으로 에러가 발생합니다. 에러가 발생한부분을 추측해보아 store/posts.js라고 생각되어 찾아봐도 문제를 찾을 수 없었습니다.

store/posts.js 코드입니다.

export const state = () => ({
  mainPosts: [],
  hasMorePost: true,
  imagePaths: [],
});

const totalPosts = 51;
const limit = 10;

export const mutations = {
  addMainPost(state, payload) {
    state.mainPosts.unshift(payload);
    state.imagePaths = [];
  },
  removeMainPost(state, payload) {
    const index = state.mainPosts.findIndex(v => v.id === payload.id);
    state.mainPosts.splice(index, 1);
  },
  loadComments(state, payload) {
    const index = state.mainPosts.findIndex(v => v.id === payload.postId);
    // 실수: state.mainPosts[index].Comments = payload.data;
    Vue.set(state.mainPosts[index], 'Comments', payload.data);
  },
  addComment(state, payload) {
    const index = state.mainPosts.findIndex(v => v.id === payload.postId);
    state.mainPosts[index].Comments.unshift(payload);
  },
  loadPosts(state,payload) {
    state.mainPosts = state.mainPosts.concat(payload);
    state.hasMorePost = payload.length === limit;
  },
  concatImagePaths(state, payload) {
    state.imagePaths = state.imagePaths.concat(payload);
  },
  removeImagePath(state, payload) {
    state.imagePaths.splice(payload, 1);
  }
};

export const actions = {
  add({ commit, state }, payload) {
    // 서버에 게시글 등록 요청 보냄
    this.$axios.post('http://localhost:3085/post', {
      content: payload.content,
      image: state.imagePaths,
    }, {
      withCredentials: true,
    })
      .then((res) => {
        commit('addMainPost', res.data);
      })
      .catch(() => {

      });
  },
  remove({ commit }, payload) {
    commit('removeMainPost', payload);
  },
  addComment({ commit }, payload) {
    this.$axios.post(`/post/${payload.postId}/comment`, {
      content: payload.content,
    }, {
      withCredentials: true,
    })
      .then((res) => {
        console.log('addComment');
        commit('addComment', res.data);
      })
      .catch(() => {

      });
  },
  loadComments({ commit }, payload) {
    this.$axios.get(`/post/${payload.postId}/comments`)
      .then((res) => {
        commit('loadComments', {
          postId: payload.postId,
          data: res.data,
        });
      })
      .catch((err) => {
        console.error(err);
      });
  },
  loadPosts({ commit, state }, payload) {
    if (state.hasMorePost) {
      this.$axios.get(`http://localhost:3085/posts?offset=${state.mainPosts.length}&limit=10`)
      .then((res) => {
        commit('loadPosts',res.data);  
      })
      .catch(()=> {

      })
    }
  },
  uploadImages({ commit }, payload) {
    this.$axios.post('http://localhost:3085/post/images', payload, {
      withCredentials: true,
    })
      .then((res) => {
        commit('concatImagePaths', res.data);
      })
      .catch(() => {

      })
  }
};

제가 헛다리를 짚는것인지 분명 잘적은것 같은데 에러가 발생합니다.

이 문제를 해결하기위해 도움 부탁드리겠습니다.

ssr vuex mysql nodejs aws vuejs

답변 1

0

제로초(조현영)

Internal Server Error라고 적혀있으면 백엔드 서버 에러입니다. 백엔드 서버 콘솔에 에러 로그 적혀 있을 겁니다.

npm run dev 할 때 에러가 발생합니다.

0

155

1

해당 강의는 리뉴얼 예정은 따로 없나요?

0

339

1

강의는 언제까지 업데이트 된 내용인가요?

0

337

2

실습 환경 문의(Node 버전)

0

374

1

로그인 새로고침시 풀림

0

304

1

안녕하세요! 로그인 유지 질문 드립니다!

0

413

1

웹 서버 관련해서 질문드립니다.

0

450

1

버전때매 질문 드립니다!!

0

319

1

이 강의는 vue3는 아닌가요??

0

379

1

vsCode에 관한 질문입니다

0

494

1

v.trim()이 타입에러가 뜹니다...

0

348

1

express.static('uploads')

0

350

2

STRING이 인식이 안되는데 이유알수있을까요?

0

454

2

<v-lsit-item-title> 에러

0

415

2

vue cli 를 실무에서도 사용하지 않으시나요?

0

326

1

선생님 처음 환경 셋팅 관련 문의드립니다.

0

392

1

nuxtServerInit 무한 로딩

0

985

3

Nginx Cookie 설정

0

734

2

상태가 204번인경우에는 어떻게 처리를 해야하나요?

0

300

1

선생님 nuxt 관련질문드립니다.

0

356

1

인덱스 비교로 삭제해도 될까요?

0

386

1

질문 드립니다!

0

335

2

안녕하세요

0

231

1

궁금한점이있습니다

0

240

1