# Vue Components

Learn about Wijmo's Vue Components in this documentation topic

## Content

<span lang="EN-US" style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1">Wijmo Vue components are available as separate npm packages. Name of each npm package is based on the corresponding control name in the core library with "vue2" included in the package name. For example, "wijmo.vue2.grid" provides Vue components for "wijmo.grid." You can install the components individually or all of them at once with "wijmo.vue2.all."</span>

```auto
npm install @mescius/wijmo.vue2.all
```

<span lang="EN-US" style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1">For more information on Wijmo npm packages, see </span>[<span style="mso-ascii-font-family:
Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos">Reference Wijmo Packages</span>](/wijmo/docs/GettingStarted/Referencing-Wijmo-NPM)***<span lang="EN-US" style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:
Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:text1">.</span>***
<span lang="EN-US" style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1">In a Vue project, there are two ways to use the Wijmo components:</span>

* <span lang="EN-US">Custom Component-Level Registration</span>
* <span lang="EN-US">Auxiliary Register Functions</span>

## Custom component level registration

<span lang="EN-US" style="mso-ascii-font-family:Aptos;
mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos">The simplest way to register Wijmo components and directives is at the custom component level. You can either use the </span>**<span lang="EN-US" style="mso-ascii-font-family:Aptos;
mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos">Composition API</span>**<span lang="EN-US" style="mso-ascii-font-family:Aptos;
mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos"> or the </span>**<span lang="EN-US" style="mso-ascii-font-family:Aptos;
mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos">Options API</span>** <span lang="EN-US" style="mso-ascii-font-family:Aptos;
mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos">to integrate Wijmo components within Vue applications. Codes below show how to import the Wijmo component and register them at the Component level using Composition API and Options API.</span>

* Code for Composition API

```auto
<script setup>
import {WjTooltip as vWjTooltip} from "@mescius/wijmo.vue2.core"
import {WjInputNumber} from "@mescius/wijmo.vue2.input"
</script>
<template>
<button v-wjTooltip="'Click me'">Click</button>
<wj-input-number ></wj-input-number>
</template>
```

* Options API

```auto
<template>
  <wj-input-number/>
   <button v-wjTooltip="'Click me'">Click</button>
  </template>
  <script>
    import {WjTooltip } from '@mescius/wijmo.vue2.core'; // import Wijmo Tooltip directive
    import { WjInputNumber } from '@mescius/wijmo.vue2.input'; // import the Wijmo InputNumber Vue3 component
    export default {
      components: {
       WjInputNumber, // register the InputNumber Component for Vue3 component
      },
      directives: {
        WjTooltip, //register the directive for Vue3 component
      },
    }
  </script>
```

## Auxiliary register functions

<span lang="EN-US">The auxiliary register functions allow you to register all components and directives from a specific Wijmo module at the application level. This approach is particularly useful when multiple components need to be registered at once, ensuring a streamlined and efficient setup. The code below </span><span style="mso-ascii-font-family:
Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos;color:black;mso-themecolor:text1" lang="EN-US">adds a </span>*<span style="font-family:
Aptos,sans-serif;mso-bidi-font-family:Aptos">wj-flex-grid</span>*  component to the App.vue file’s template section:

* **<span style="mso-ascii-font-family:Aptos;
    mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">main.js</span>**

```auto


import {createApp } from 'vue' 
import App from './App.vue' 
import '@mescius/wijmo.styles/wijmo.css'; 
import{registerGrid} from "@mescius/wijmo.vue2.grid" 
let app = createApp(App); 
    registerGrid(app);
    app.mount('#app')
```

* **<span style="mso-ascii-font-family:Aptos;
    mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">app.vue</span>**

```auto
<script setup> 
import { ref } from 'vue' 
// variables 
const data = ref(getData()) 
//methods 
function getData() { 
    var data = []; 
    var countries="US,Japan,India,Italy,UK".split(","); 
    for (let i = 0; i < 5; i++) { 
        data.push({ 
            id: i+1,  
            country: countries[i%countries.length], 
            sales: Math.random() * 1000, 
            downloads: Math.random() * 1000 
                }); 
    } 
  return data; 
} 
</script> 
<template> 
<wj-flex-grid :itemsSource="data"></wj-flex-grid> 
</template> 
```

<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US">You only need to import registerModuleName from Vue modules once, preferably in the root module of your Single Page Application. For instance, the registerInput method is imported from the wijmo.vue2.input module and called with the app instance, which represents the application.</span>

> type=note
> ***<span lang="EN-US" style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
> Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
> mso-themecolor:text1">Note:</span>*** *<span lang="EN-US" style="mso-ascii-font-family:
> Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
> Aptos;color:black;mso-themecolor:text1">Wijmo Vue components are designed for use in template markup.</span>*

<span style="mso-ascii-font-family:
Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
Aptos;color:black;mso-themecolor:text1" lang="EN-US">To create a Wijmo control in code, use the corresponding Wijmo control from the core module instead. That is, use "wijmo.grid" to create the FlexGrid control in code and not "wijmo.Vue2.grid".</span>

```auto
import { FlexGrid } from '@mescius/wijmo.grid'; 
let flex = new FlexGrid('#host_element');
```

## <span lang="EN-US">Adding Wijmo CSS</span>

<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US">Wijmo ships </span>**<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US">@mescius/wijmo.styles</span>**<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US"> npm package which contains the following two files:</span>

* <span style="mso-ascii-font-family:
    Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">Wijmo.css - includes styles for all controls</span>
* <span style="mso-ascii-font-family:
    Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">wijmo-core.css - truncated version of wijmo.css. It excludes styles for Enterprise controls.</span>

<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US">You can add styles to your Vue application by referencing in one of the following places:</span>

1. **Root Vue component app.vue:** Add the following import statement to import styles inside the **\<styles>** tag

    ```auto
    import '@mescius/wijmo.styles/wijmo.css';
    ```
2. **Main.JS** – In case of using **Composition API** with global registration\*\*,\*\* add the following code at the top of the js file:

    ```auto
    import '@mescius/wijmo.styles/wijmo.css';
    ```

## Vue Markup Syntax

<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US">Wijmo Vue components use consistent naming conventions in template markup. The HTML element and attribute names used for components can be easily inferred from component classes and member names by using the following simple rules:</span>

* <span style="mso-ascii-font-family:
    Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">Vue3 does not have any specific convention for naming of attributes, properties, and events. That is, you can use camelCase as well as lower-case-dash to specify Wijmo component properties and events.</span>
* <span style="mso-ascii-font-family:
    Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">The HTML element name representing a Wijmo </span>**<span style="mso-ascii-font-family:
    Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US">component</span>**<span style="mso-ascii-font-family:
    Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:
    Aptos;color:black;mso-themecolor:text1" lang="EN-US"> is specified using lower-case-dash syntax.</span><span style="mso-spacerun:yes">  </span>For example, write  **WjInputNumber** component as **wj-input-number.**

    ```auto
    <wj-input-number :value="amount"></wj-input-number>
    ```
* <span style="font-size:12.0pt;line-height:116%;font-family:Aptos,sans-serif;
    mso-fareast-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
    mso-themecolor:text1;mso-font-kerning:0pt;mso-ligatures:none;mso-ansi-language:
    EN-US;mso-fareast-language:JA;mso-bidi-language:AR-SA" lang="EN-US">For writing the component markup in camelCase, import the Component from the module and specify in the component. For</span> **<span style="font-size:12.0pt;line-height:116%;font-family:Aptos,sans-serif;
    mso-fareast-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
    mso-themecolor:text1;mso-font-kerning:0pt;mso-ligatures:none;mso-ansi-language:
    EN-US;mso-fareast-language:JA;mso-bidi-language:AR-SA" lang="EN-US">Auxiliary registration method,</span>** <span style="font-size:12.0pt;line-height:116%;font-family:Aptos,sans-serif;
    mso-fareast-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
    mso-themecolor:text1;mso-font-kerning:0pt;mso-ligatures:none;mso-ansi-language:
    EN-US;mso-fareast-language:JA;mso-bidi-language:AR-SA" lang="EN-US">specify each component that you plan to use in the project</span>
    * **Main.JS**

        ```auto
        import {WjInputNumber,
        WjInputColor} from "@mescius/wijmo.vue2.input"
        let app = createApp(App);
        // register the Wijmo
        Components
        app.component('WjInputNumber',WjInputNumber).component('WjInputColor',WjInputColor);
        app.mount('#app');`
        ```
    * **app.vue**

        ```auto
        <WjInputNumber></WjInputNumber><br\>
        <WjInputColor></WjInputColor>
        ```
    * <span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
        mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:
        text1" lang="EN-US">In case of one-way binding, prepend the names with the </span>**<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
        mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:
        text1" lang="EN-US">v-bind:</span>**<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
        mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:
        text1" lang="EN-US"> directive (or its </span>**<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
        mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:
        text1" lang="EN-US">':'</span>**<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
        mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:
        text1" lang="EN-US"> shorthand), except while binding a string type property to a string constant. One-way binding is used to set the property’s value or event handler.</span>
    * <span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
        mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;mso-themecolor:
        text1" lang="EN-US">For the two-way binding between form inputs and component data, use the v-model directive. When you use v-model, Vue automatically handles updating the data property and the input element's value.</span>

        ```auto
        <wj-input-number 
         v-model:value="amount" //two-way binding to a component property 
        format="n0" //binding to a string constant  
        :is-read-only="true" //binding to Boolean
        :valueChanged="valueChanged"> //event binding 
        </wj-input-number>
        ```

### Event handlers

<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
mso-themecolor:text1" lang="EN-US">Wijmo event handlers are defined as functions with two parameters: sender and event argument. </span><span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;mso-hansi-font-family:
Aptos;mso-bidi-font-family:Aptos" lang="EN-US">While binding to a component event, you must define an event handler method according to the API type used by your Vue component.</span><span style="mso-spacerun:yes">   </span>

* **<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
    Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
    mso-themecolor:text1" lang="EN-US">Options API</span>**

    ```auto
    <template>
    <wj-input-number 
    :value="amount"
    :value-changed="onValueChanged"> 
    </wj-input-number>
     </template> 
    <script>
     ... 
    let App = {   
     ...  
    methods:
    { 
    onValueChanged:function(sender,args) {
    this.amount =sender.value;
    },
    ...
     }; 
    ...
    </script>
    ```
* **<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
    Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
    mso-themecolor:text1" lang="EN-US">Composition API</span>**

    ```auto
    <script
    setup>
     import {ref} from "vue" 
    const amount =
    ref(100) // variables
    //methods and event handler methods
    function valueChanged(sender,args){
    amount.value = sender.value;
    }
    </script>
    <template>
    <button
    v-wjTooltip="'Click me'">Click</button>
    <wj-input-number :value="amount"
    :valueChanged="valueChanged"></wj-input-number>
    </template>
    ```

### The "initialized" Event

<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos" lang="EN-US">All Wijmo Vue components have an </span><span style="font-family:Consolas;
mso-fareast-font-family:Consolas;mso-bidi-font-family:Consolas" lang="EN-US">initialized</span><span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:Aptos;
mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos" lang="EN-US"> event, triggered after the control is added to the page and has been initialized. You can use this event for extra setup beyond setting properties in markup. </span><span style="color:black;mso-themecolor:text1">The signature of the handler function is the same as any other Wijmo event handlers.</span>

* **<span style="mso-ascii-font-family:Aptos;mso-fareast-font-family:
    Aptos;mso-hansi-font-family:Aptos;mso-bidi-font-family:Aptos;color:black;
    mso-themecolor:text1" lang="EN-US">Options API</span>**

    ```auto
    <template>
    <wj-flex-grid:initialized="initGrid">
    </wj-flex-grid>
    </template>
    <script>
    ...
    let App = {
    ...
    methods:
    {
    initGrid:function(grid,args) {
    grid.mergeManager = new CustomMerge(grid);
     },  
    ...
    }; 
    ...
    </script>
    ```
* **Composition API**

    ```auto
    <script
    setup>
    function initGrid(sender,
    args){
    //your code
     } 
    </script> 
    <template>  
    <wj-flex-grid
    :initialized="initGrid">
    </wj-flex-grid> 
    </template>
    ```


<br>
<br>
<br>
