Nuxt Composables

up:: Nuxt ⚐

Composables

  • Using data across components.
  • Nuxi is a command line utility for working with nuxt
    • you can scaffold different files

In the useCourse.js file.

import courseData from './courseData';
 
export const useCourse = () => {
	return courseData;
}

In the lesson.vue course.

<script setup>
const course = useCourse();
</script>

Questions: What does the computed() mean in his code?

Composables

Cite

Any reactive logic can become a composable.

Any reactive logic from Vue, we can turn into a composable.

Three types of composables:

  1. Single use
  2. Reusable
  3. Generic (anything in VueUse eg. useLocalStorage)

Any files stored in the composable folder, are auto-imported as components to be available anywhere.