Integrations
How to use this SDK within your favorite Framework. 🚀
Nuxt 2
In order to use Strapi SDK
globally you have to setup a plugin
& add it into the nuxt.config.js
file:
~/plugins/strapi.js
import Strapi from "strapi-sdk-js";
export default ({ app }, inject) => {
const strapi = new Strapi({
// options
});
inject("strapi", strapi);
};
nuxt.config.js
export default {
// ...
plugins: ["~/plugins/strapi"],
};
You can now use it globally thanks this.$strapi
in components & app.$strapi
in asyncData
function.
Nuxt 3
Unlike Nuxt 2, you will only have to setup a plugin
and then you will just have to retrieve $strapi
from useNuxtApp
everywhere you want to use it:
~/plugins/strapi.js
import { defineNuxtPlugin } from "#app";
import Strapi from "strapi-sdk-js";
export default defineNuxtPlugin(() => {
const strapi = new Strapi({
// options
});
return {
provide: {
strapi,
},
};
});
<script setup>
const {$strapi} = useNuxtApp(); const restaurants = await
$strapi.find("restaurants");
</script>