29
loading...
This website collects cookies to deliver better user experience
yarn global add @vue-storefront/cli
vsf init lexascms-tutorial
lexascms-tutorial
directory which will contain the code for your new project.cd lexascms-tutorial
yarn install
yarn run dev
yarn add vsf-lexascms
vsf-lexascms
integration in your projects nuxt.config.js
file as follows:export default {
// ...
buildModules: [
// ...
['vsf-lexascms/nuxt']
]
// ...
};
middleware.config.js
file in the root of your project and add the following configuration:YOUR_SPACE_ID
with your actual space ID, which can be found in the Settings > General section of your space control panel.module.exports = {
integrations: {
// ...
lexascms: {
location: 'vsf-lexascms/server',
configuration: {
spaceId: 'YOUR_SPACE_ID'
}
}
}
};
useContent
composable. Before we make any changes to our homepage, let's take a look at how it works.useContent
composable is imported directly from your CMS integration like so:import { useContent } from 'vsf-lexascms';
const { search, content, loading, error } = useContent();
useContent
composable works, let's use it to fetch the content for your homepage's hero banner.pages/Home.vue
file in your project, and adding the below import statements.onSSR
helper function from Vue Storefront. We'll use this to ensure that content is only fetched during server-side rendering.<script>
// ...
import { onSSR } from '@vue-storefront/core';
import { useContent } from 'vsf-lexascms';
export default {
// ...
}
</script>
setup
function as shown below.useContent
composable and onSSR
helper function to retrieve all of the promo banners from LexasCMS. These are then made available to your template as the promoBanners
variable.<script>
// ...
export default {
// ...
setup() {
const { content: promoBanners, search } = useContent();
onSSR(async () => {
await search({
type: 'collection',
contentType: 'promoBanner',
params: {
include: 'backgroundImage'
}
});
});
return { promoBanners }
},
// ...
}
</script>
pages/Home.vue
file and replace the current usage of the SfHero
component so that it looks as follows:<template>
<div id="home">
<SfHero class="hero">
<SfHeroItem
v-for="promoBanner in promoBanners"
:key="promoBanner.id"
:title="promoBanner.heading"
:subtitle="promoBanner.subHeading"
:button-text="promoBanner.buttonText"
:image="promoBanner.backgroundImage.url"
/>
</SfHero>
<!-- ... -->
</div>
</template>
promoBanners
variable from the previous step, and render each of the retrieved promo banners using the SfHeroItem
component from Storefront UI.useContent
composable in Vue Storefront 2.