[vue router] 객체 형식으로 params 전달

jieun·2022년 11월 14일
0

vue

목록 보기
3/3

vue router 생성 시 파라미터를 통해 객체를 컴포넌트에 전달할 때
JSON.stringifh()으로 처리

<template>
  <div @click="onDroneClick(sortie)">
    클릭클릭
  </div>
</template>

<script>
export default {
  methods: {
    onClick (exam) {
      this.$router.push({ name: 'ExamPage', params: { id: exam.id, exam: JSON.stringify(exam) }})
    }
  }
}
</script>
<template>
  <div>
    {{exam.id}}, {{exam.title}}
  </div>
</template>

<script>
export default {
  name: 'ExamPage',
  data () {
    return {
      exam: this.$route.params.exam
    }
  },
}
</script>
profile
개발새발 블로그

0개의 댓글