🔥 隆重推出我們的新專案 t0ggles - 您終極的專案管理工具! 🔥

使用方式

在完成安裝程序後,我們就可以開始在我們的 Vue 應用程式中使用 Konsta UI 元件。

元件

這個過程相當直接,我們需要從 konsta/vue 匯入 Konsta UI Vue 元件。

<template>
  ...
  <k-block>
    <p>This is block with text</p>
  </k-block>
  <k-block class="space-y-4">
    <p>Here comes the button</p>
    <k-button>Action</k-button>
  </k-block>
  ...
</template>
<script>
  /* App.vue */
  import { kBlock, kButton } from 'konsta/vue';

  export {
    components: {
      kBlock,
      kButton,
    },
  }
</script>

App 元件

我們假設您將 Konsta UI 元件與其他框架(如 Framework7Ionic)一起使用。

但是,如果您只使用 Konsta UI,則需要使用 Konsta UI 的 App 元件 包裹我們所有的元件。

App 元件 中,我們可以定義全域主題(iOS 或 Material)和其他有用的全域設定。

<template>
  <k-app theme="ios">
    <k-page>
      <k-navbar title="My App" />
      <k-block>
        <p>Here comes my app</p>
      </k-block>
    </k-page>
  </k-app>
</template>
<script>
  import { kApp, kPage, kNavbar, kBlock } from 'konsta/vue';

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

Konsta UI 提供器

如果您確實將 Konsta UI 與其他框架一起使用,我們仍然可以(而且應該)指定 Konsta UI 的全域設定(例如主題)。在這種情況下,我們需要使用 KonstaProvider

我們還需要將 k-iosk-material 類別新增到應用程式的根元素中。

<template>
  <!-- Wrap our app with KonstaProvider -->
  <k-provider theme="ios">
    <!-- We add extra `k-ios` class to the app root element -->
    <f7-app theme="ios" class="k-ios">
      <f7-view>
        <f7-page>
          <f7-navbar title="My App" />
          <!-- Konsta UI components -->
          <k-block>
            <p>Here comes my app</p>
          </k-block>
          <k-block class="space-y-4">
            <p>Here comes the button</p>
            <k-button>Action</k-button>
          </k-block>
        </f7-page>
      </f7-view>
    </f7-app>
  </k-provider>
</template>

<script>
  /* App.vue */
  // we use main App and Router components from Framework7
  import { f7App, f7View, f7Page, f7Navbar } from 'framework7-vue';
  // we use KonstaProvider instead
  import { konstaProvider, kBlock, kButton } from 'konsta/vue';

  export default {
    components: {
      f7App,
      f7View,
      f7Page,
      f7Navbar,
      konstaProvider,
      kBlock,
      kButton,
    },
  };
</script>
程式碼授權於 MIT.
2022 © Konsta UI 由 nolimits4web.