useDirectusCollections


Check out the Directus Collections documentation.

getCollections

List all collections.

  • Arguments:
    • None
  • Returns: Array<T>
pages/collections.vue
<script setup>const { getCollections } = useDirectusCollections();const router = useRouter();const fetchCollections = async () => {  const collections = await getCollections();};</script>

getCollection

Retrieve a specific collection by name

pages/collections.vue
<script setup>const { getCollection } = useDirectusCollections();const router = useRouter();const fetchCollection = async () => {  const collectionParams = { collection: "Page" };  const collection = await getCollection(collectionParams);};</script>

createCollection

Create a new collection.

pages/collection.vue
<script setup>const { createCollection } = useDirectusCollections();const createCollection = async () => {  try {    await createCollection({       collection: "News",       meta: {        icon: 'article'      }   });  } catch (e) {}};</script>

deleteCollection

Delete a specific collection

pages/collection.vue
<script setup>const { deleteCollection } = useDirectusCollections();const deleteArticles: void = async () => {  try {    await deleteCollection({ collection: "Articles" });  } catch (e) {}};</script>

updateCollection

Update collection metadata. Note: only meta data is updatable.

pages/collection.vue
<script setup>const { updateCollection } = useDirectusCollections();const updateCollection: Collection = async () => {  try {    await updateCollection<Collection>({       collection: "News",       meta: {        icon: 'page'      }     });  } catch (e) {}};</script>