Konsta UI & Nuxt

Let's see how to use Konsta UI Vue components with Nuxt.

Because Konsta UI comes with components only for Vue.js v3, it compatible only with Nuxt 3 as well.

Create Nuxt Project

First, create a Nuxt project

Install Tailwind CSS

We can follow official Tailwind CSS installation Guide

Tailwind CSS Styles

Create a assets/globals.css file with the following content to include Tailwind CSS:

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap');
@tailwind base;
@tailwind components;
@tailwind utilities;

Install Konsta UI

Now in created Nuxt project, we need to install Konsta UI:

npm i konsta

And in your tailwind.config.js file we should extend config with Konsta UI's config:

// import konstaConfig config
const konstaConfig = require('konsta/config');

// wrap config with konstaConfig config
module.exports = konstaConfig({
  content: [
    './components/*.{js,ts,jsx,vue}',
    './pages/*.{js,ts,jsx,vue}',
    './*.{js,ts,jsx,vue}',
  ],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
});

App Component

Now we need to setup main App component so we can set some global parameters (like theme).

We need to wrap whole app with App in the ./app.vue:

<template>
  <!-- Wrap our app with App component -->
  <k-app theme="ios">
    <NuxtPage />
  </k-app>
</template>

<script>
  import { kApp } from 'konsta/vue';
  import './assets/main.scss';

  export default {
    components: {
      kApp,
    },
  };
</script>

Example Page

Now when everything is set up, we can use Konsta UI React components in our Nuxt pages.

For example, let's open pages/index.vue and change it to the following:

<template>
  <k-page>
    <k-navbar title="My App" />

    <k-block strong>
      <p>Here is your Next.js & Konsta UI app. Let's see what we have here.</p>
    </k-block>
    <k-block-title>Navigation</k-block-title>
    <k-list>
      <k-list-item href="/about/" title="About" />
      <k-list-item href="/form/" title="Form" />
    </k-list>

    <k-block strong className="flex space-x-4">
      <k-button>Button 1</k-button>
      <k-button>Button 2</k-button>
    </k-block>
  </k-page>
</template>
<script>
  // Konsta UI components
  import {
    kPage,
    kNavbar,
    kBlock,
    kButton,
    kList,
    kListItem,
    kLink,
    kBlockTitle,
  } from 'konsta/vue';

  export default {
    components: {
      kPage,
      kNavbar,
      kBlock,
      kButton,
      kList,
      kListItem,
      kLink,
      kBlockTitle,
    },
  };
</script>

As a result we should see the following page:

konsta-next
Code licensed under MIT.
2021 © Konsta UI by nolimits4web.