Skip to content

Usage ​

Installation ​

bash
npm install jskos-vue

See below for usage in browser.

Requirements ​

For a Node.js project, it is recommended to use Vite. For access to JSKOS data via web APIs we recommend cocoda-sdk.

The library also supports Vue I18n, see Localization.

Globally in a Vue project ​

This adds all of jskos-vue's components globally to your Vue project (src/main.js):

js
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)

import * as JskosVue from "jskos-vue"
app.use(JskosVue)

// Import stylesheet
import "jskos-vue/dist/style.css"

app.mount('#app')

Globally in a Vue project (individual components) ​

This adds individual components (tree-shakable) globally to your Vue project (src/main.js):

js
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)

import { ItemName } from "jskos-vue"
app.use(ItemName)

// Import stylesheet
import "jskos-vue/dist/style.css"

app.mount('#app')

Locally in a Vue project ​

You can also add individual components where needed (e.g. in some SFC, tree-shakable):

js
import { defineComponent } from "vue"
import { ItemName } from "jskos-vue"
// Import stylesheet
import "jskos-vue/dist/style.css"

export default defineComponent({
  // ...
  components: {
    ItemName,
  },
  // ...
})

Browser ​

The library can be used in the browser, for example via jsDelivr.

Fully working HTML example:

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue App</title>
    <!-- jskos-vue stylesheet and required libraries (adjust version for updates) -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jskos-vue/dist/style.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-flexible-table@1.1.0/dist/style.css">
    <script type="importmap">
    {
      "imports": {
        "vue": "https://cdn.jsdelivr.net/npm/vue@3/dist/vue.esm-browser.js",
        "jskos-tools": "https://esm.sh/jskos-tools@1.3.1",
        "vue-scrollto": "https://esm.sh/vue-scrollto@2.20.0",
        "jskos-vue-tabs": "https://cdn.jsdelivr.net/npm/jskos-vue-tabs@0.1.8/dist/jskos-vue-tabs.js",
        "jskos-vue": "https://cdn.jsdelivr.net/npm/jskos-vue/dist/jskos-vue.js",
        "vue-flexible-table": "https://cdn.jsdelivr.net/npm/vue-flexible-table@1.1.0/dist/vue-flexible-table.js"
      }
    }
    </script>
  </head>
  <body>
    <div id="app">
      <button @click="scroll('uri:25')">Scroll to 25</button>
      <item-list
        ref="itemList"
        style="height: 100px; overflow-y: scroll; border: 1px solid black; margin-top: 20px;"
        :items="Array.from({ length: 50 }, (v, i) => ({ uri: `uri:${i}`, notation: [`${i}`], prefLabel: { en: `Test ${i}` }}))" />
    </div>
    <script type="module">
      import * as Vue from "vue"
      import * as JskosVue from "jskos-vue" 
      Vue.createApp({
        methods: {
          scroll(uri) {
            this.$refs.itemList.scrollToUri(uri)
          }
        },
      }).use(JskosVue).mount("#app")
    </script>
  </body>
</html>

See examples directory in the git repository of jskos-vue for an additional example.

Localization ​

The library comes with translated messages in English and German. Additional messages can be provided with Vue I18n or its subset petite-vue-i18n.

Without Vue I18n, UI messages use the available component translations and jskos-tools language preferences. Applications cannot override or extend those UI messages globally.

UI messages and JSKOS content languages are selected independently. Content labels prefer an explicit component language, configured jskos-tools language preferences, the Vue I18n locale, and finally an available JSKOS language.

See useLocale for UI messages and useContentLanguage for JSKOS content.

The following demo uses separate controls for the UI locale and content language. Select “Follow UI locale” to disable explicit content preferences.