Route Parameter ใน NuxtJS

wave
มานพ กองอุ่น 21 ธ.ค. 2019 21:32:26 5,468

เราสามารถเข้าถึง route parameter ของ nuxtjs ได้โดยใช้ $route โดยสามารถกำหนดในไฟล์ดังนี้ {{$route.params.id}}

ตัวอย่างไฟล์ pages/users/_id/index.vue

<template>
    <h1>Posts page id {{$route.params.id}}</h1>
</template>

ทดลองเปิดใน browser http://localhost:3000/posts/99 จะปรากฏหน้า web application ดังนี้


ความคิดเห็น

หากบทเรียนรู้มีความผิดพลาดประการใด หรือมีข้อเสนอแนะกรุณาแจ้ง contact@programmerthailand.com