inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Nuxt.js 시작하기

상세 페이지의 장바구니 담기 기능 구현

페이지의 장바구니 담기 기능 관련 오류

396

kyle3444

작성한 질문수 14

1

<template>
    <div>
    <div class="container">
      <div class="main-panel">
        <img
          class="product-image"
          :src="product.imageUrl"
          :alt="product.name"
        />
      </div>
      <div class="side-panel">
        <p class="name">{{ product.name }}</p>
        <p class="price">{{ product.price }}</p>
        <button type="button" @click="addToCart">Add to Cart</button> 
      </div>
    </div>
  </div>
</template>

<script>
import {fetchProductById} from '@/api/index'

export default {
    async asyncData({ params }) {
        const response = await fetchProductById(params.id);
        const product = response.data
        return{ product }
    },
    methods: {
      addToCart() {
        this.$store.commit('addCartItem',this.product);
        this.$router.push('/cart')
        console.log("hi success")
      }
    }
    
}
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  margin: 2rem 0;
}
.product-image {
  width: 500px;
  height: 375px;
}
.side-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 220px;
  text-align: center;
  padding: 0 1rem;
}
</style>
export const state= () => ({
    cartItems: [''],
})

export const mutations = {
    addCartItem(state, cartItem) {
        state.cartItems.push(cartItem)
    },
}

코드를 다음과 같이 작성했는데 강의처럼 addCartItem이 안나옵니다.D544831B-D434-49FD-83AD-2C648614E48C.jpeg

vuejs nuxtjs ssr

답변 1

0

캡틴판교

안녕하세요, 개발자 도구 UI가 변경되어서 헷갈리셨겠네요 ㅜㅜ 첨부해 주신 도구의 세번째 탭을 클릭해 보시면 mutations을 확인하실 수 있을 겁니다 :)

image

판교님, 50% 학생 할인 쿠폰

0

140

2

캡틴님 커리어 질문 있습니다

0

77

1

nuxt 최신버전 설치 후 layouts 없어서 직접 폴더 생성 후 문제

1

349

1

vue나 nuxt 새로운 강의는 출시 예정이 없으실까요?

0

187

1

24년 강의를 들으면서 에러나는 부분 정리

2

339

2

공식홈페이지에 설치방법이 바뀐거같아요

1

405

3

layouts폴더와 default.vue에대해서 궁금한 점 있습니다!

1

383

2

자료가 없습니다.

1

285

2

에러 페이지 정의 방법 강의 문의

1

333

2

SSG -> SSR 배포 방식 전환

1

526

2

갑자기 화면에 에러가 나오네요..

1

449

2

마지막 강의까지 작성된 코드

1

295

2

JSON Server Operator 링크에 Operator 가 없습니다.

1

224

2

Vue2 EOL 관련해서..

1

463

2

env.baseUrl 문제

1

625

2

블로그 기능 질문입니다!

1

458

3

node 버전 문제 질문입니다.

1

224

1

폴더구조 다른것 안내 부탁드려요

1

458

1

npm run generate 배포

1

678

2

캡틴판교 선생님 너무 궁금해서 질문드립니다 ㅜ

1

326

2

nuxt.config.js 에서 baseurl 지정하는 방법

2

992

1

db.json 안에 이미지 아래 본문 처럼 바꾸면 랜덤으로 나옵니다.

2

611

3

axios 설치 후 새로고침 시 에러 발생할 때 해결 방법 입니다.

2

769

2

SSG 배포가 현재 상품,장바구니에는 맞지 않는 배포방식인거죠?

1

387

2