Frontend setup
Frontend setup
Add the crouton admin UI to a Vue 3 application.
Install
pnpm add @ghentcdh/crouton-vuePeer dependencies (vue, vue-router, axios, …) are installed automatically by pnpm and npm.
Styles
Import the crouton styles once, in your application entry:
// main.ts
import '@ghentcdh/crouton-vue/styles.css';Bootstrap
Initialize crouton via CroutonPlugin before mounting the app. The plugin configures the API client and fetches /_app/layout from the backend to build the sidebar:
// main.ts
import { createApp } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';
import axios from 'axios';
import { CroutonPlugin, CroutonRouter } from '@ghentcdh/crouton-vue';
import App from './app/App.vue';
const api = axios.create({ baseURL: 'http://localhost:3000' });
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/admin', children: [...CroutonRouter] },
],
});
const app = createApp(App);
app.use(CroutonPlugin(api, { title: 'My App', router }));
app.use(router);
app.mount('#root');Any pre-configured AxiosInstance works — add your auth interceptors to it before passing it to
CroutonPlugin.
Mount the routes
Spread CroutonRouter under the path where the admin UI should live:
// router/index.ts
import { createRouter, createWebHistory } from 'vue-router';
import { CroutonRouter } from '@ghentcdh/crouton-vue';
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', name: 'home', component: HomeView },
{
path: '/admin',
name: 'admin',
children: [...CroutonRouter],
},
],
});
export default router;Navigating to /admin/crouton/<resource> now renders the complete admin view — table, filters, and forms — for that resource. Nothing else to configure.
Navigate programmatically with the named route:
import { CROUTON_FORM } from '@ghentcdh/crouton-vue';
router.push({ name: CROUTON_FORM, params: { formId: 'book' } });Sidebar
useCrouton() exposes the sidebar built from /_app/layout:
const { sidebar } = useCrouton();Use it to render your own navigation, or hide resources from it via sidebar.hide in their resource.json.
Pass router to CroutonPlugin and the status page is registered automatically. See Status page.
Plugin options
CroutonPlugin accepts an optional second argument to configure global defaults:
app.use(
CroutonPlugin(api, {
title: 'My App', // App title (overridden by backend if not set)
router, // Vue Router instance — registers crouton routes (status page, etc.)
showErrors: false, // Show raw validation errors below every CroutonForm (default: false)
debugValue: false, // Show live form values below every CroutonForm (default: false)
autoSave: false, // Enable autosave globally for all CroutonForms (default: false)
defaults: {}, // Default form values injected for $user and other dynamic tokens
isDev: false, // Enable dev-only features (resource editor, publish button, etc.)
renderers: [], // Extra JsonForms control renderers
readonlyRenderers: [], // Extra renderers for readonly/view mode
cellRenderers: [], // Extra table cell renderers
customComponents: [], // Extra custom components
}),
);showErrors and debugValue can be overridden per form via the matching props:
<!-- disable error display for this form only -->
<CroutonForm :show-errors="false" ... />
<!-- enable debug output for this form only -->
<CroutonForm :debug-value="true" ... />Advanced: schemas in custom views
For custom pages that want the resource schemas directly, use the cached form definitions:
const { getFormDef } = useCrouton();
const formDef = await getFormDef('book'); // GET /book/schemas (cached)
// formDef.schemas.table / .form / .view / .filter