<script setup>
タグの中で参照するには次のように porps.
を付けて記述する。
<script setup>
const props = defineProps({
id: {
type: Number,
required: true
},
title: {
type: String,
required: true
},
})
function navigateToPage() {
// defineProps で宣言した props を参照
window.location.href = '/articles/' + props.id
}
</script>
<template>
<div class="card" @click="navigateToPage">
<!-- props.title と書く必要はない -->
<h2>{{ title }}</h2>
</div>
</template>
参考