SKILL.blade.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---
  2. name: inertia-vue-development
  3. description: "Develops Inertia.js v1 Vue client-side applications. Activates when creating Vue pages, forms, or navigation; using Link or router; or when user mentions Vue with Inertia, Vue pages, Vue forms, or Vue navigation."
  4. license: MIT
  5. metadata:
  6. author: laravel
  7. ---
  8. @php
  9. /** @var \Laravel\Boost\Install\GuidelineAssist $assist */
  10. @endphp
  11. # Inertia Vue Development
  12. ## Documentation
  13. Use `search-docs` for detailed Inertia v1 Vue patterns and documentation.
  14. ## Basic Usage
  15. ### Page Components Location
  16. Vue page components should be placed in the `{{ $assist->inertia()->pagesDirectory() }}` directory.
  17. ### Page Component Structure
  18. Important: Vue components must have a single root element.
  19. @verbatim
  20. @boostsnippet("Basic Vue Page Component", "vue")
  21. <script setup>
  22. defineProps({
  23. users: Array
  24. })
  25. </script>
  26. <template>
  27. <div>
  28. <h1>Users</h1>
  29. <ul>
  30. <li v-for="user in users" :key="user.id">
  31. {{ user.name }}
  32. </li>
  33. </ul>
  34. </div>
  35. </template>
  36. @endboostsnippet
  37. @endverbatim
  38. ## Client-Side Navigation
  39. ### Basic Link Component
  40. Use `<Link>` for client-side navigation instead of traditional `<a>` tags:
  41. @boostsnippet("Inertia Vue Navigation", "vue")
  42. <script setup>
  43. import { Link } from '@inertiajs/vue3'
  44. </script>
  45. <template>
  46. <div>
  47. <Link href="/">Home</Link>
  48. <Link href="/users">Users</Link>
  49. <Link :href="`/users/${user.id}`">View User</Link>
  50. </div>
  51. </template>
  52. @endboostsnippet
  53. ### Link With Method
  54. @boostsnippet("Link With POST Method", "vue")
  55. <script setup>
  56. import { Link } from '@inertiajs/vue3'
  57. </script>
  58. <template>
  59. <Link href="/logout" method="post" as="button">
  60. Logout
  61. </Link>
  62. </template>
  63. @endboostsnippet
  64. ### Programmatic Navigation
  65. @boostsnippet("Router Visit", "vue")
  66. <script setup>
  67. import { router } from '@inertiajs/vue3'
  68. function handleClick() {
  69. router.visit('/users')
  70. }
  71. // Or with options
  72. function createUser() {
  73. router.visit('/users', {
  74. method: 'post',
  75. data: { name: 'John' },
  76. onSuccess: () => console.log('Success!'),
  77. })
  78. }
  79. </script>
  80. @endboostsnippet
  81. ## Form Handling
  82. ### Using `router.post`
  83. @boostsnippet("Form with router.post", "vue")
  84. <script setup>
  85. import { router } from '@inertiajs/vue3'
  86. import { reactive, ref } from 'vue'
  87. const form = reactive({
  88. name: '',
  89. email: '',
  90. })
  91. const processing = ref(false)
  92. function handleSubmit() {
  93. processing.value = true
  94. router.post('/users', form, {
  95. onFinish: () => processing.value = false,
  96. })
  97. }
  98. </script>
  99. <template>
  100. <form @submit.prevent="handleSubmit">
  101. <input type="text" v-model="form.name" />
  102. <input type="email" v-model="form.email" />
  103. <button type="submit" :disabled="processing">
  104. Create User
  105. </button>
  106. </form>
  107. </template>
  108. @endboostsnippet
  109. ## Inertia v1 Limitations
  110. Inertia v1 does not support these v2 features:
  111. - `<Form>` component
  112. - Deferred props
  113. - Prefetching
  114. - Polling
  115. - Infinite scrolling with `WhenVisible`
  116. - Merging props
  117. Do not use these features in v1 projects.
  118. ## Server-Side Patterns
  119. Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines.
  120. ## Common Pitfalls
  121. - Using traditional `<a>` links instead of Inertia's `<Link>` component (breaks SPA behavior)
  122. - Using multiple root elements in Vue components (while Vue 3 supports this, a single root is recommended for Inertia v1 compatibility)
  123. - Trying to use Inertia v2 features (deferred props, `<Form>` component, etc.) in v1 projects
  124. - Using `<form>` without preventing default submission (use `@submit.prevent`)
  125. - Not handling loading states during form submission