0
0

【Vue3】definePropsで宣言したpropsを参照する

Posted at

<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>

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0