23.2.5 • Published 9 days ago

devextreme-vue v23.2.5

Weekly downloads
5,378
License
MIT
Repository
github
Last release
9 days ago

DevExtreme Vue UI and Visualization Components

Build Status Project Status NPM

This project allows you to use DevExtreme Widgets as Vue Components.

Getting Started

You can try this live example (no need to install anything).

See the sections below if you prefer using a local development environment.

Prerequisites

Node.js and npm are required

Install DevExtreme

Install the devextreme and devextreme-vue npm packages:

npm install --save devextreme@18.1 devextreme-vue

Additional Configuration

The further configuration steps depend on which build tool, bundler or module loader you are using. Please choose the one you need:

Import DevExtreme Modules and Themes

Import DevExtreme modules in a DevExtreme component's file.

import { DxButton } from 'devextreme-vue';

DevExtreme themes can be imported only once in your application's main file:

import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.compact.css';

See the Predefined Themes guide for more information on DevExtreme themes.

Use DevExtreme Components

You can use DevExtreme components in a single file component...

<template>
    <dx-button :text='text'/>
</template>

<script>
import { DxButton } from 'devextreme-vue';
export default {
  name: 'HelloWorld',
  data() {
    return {
      text: 'Hello!'
    };
  },
  components: {
    DxButton
  }
};
</script>

... in a jsx render function

import Vue from 'vue';
import { DxButton } from 'devextreme-vue';


new Vue({
  el: '#app',
  data: function() {
    return {
      text: "Hello!"
    }
  },
  render: function(h) {
    return (
      <DxButton text={this.text} />
    )
  }
});

... or directly in a vue template

new Vue({
  el: '#app',
  components: { DxButton },
  template: '<dx-button :text="text" />',
  data() {
    return {
      text: 'Hello!'
    };
  }
});

API Reference

DevExtreme Vue components are similar to the DevExtreme JavaScript API but use Vue syntax for specifying widget options, subscribing to events and custom template declaration.

Component Configuration

Set Component Option

  • A constant string value (for example, the Button text):

    <dx-button text="Simple button" />
  • A constant non-string value (for example, the CheckBox value):

    <dx-check-box :value="true" />
  • A value from a component data:

    <dx-button :text="text" />

    where : is a shorthand for v-bind directive.

Two-way Binding

Use the sync modifier to bind a bindingProperty to a widget option:

<dx-text-box :value.sync="bindingProperty" />

Editors Value Binding

The DevExtreme Vue editors also support v-model directive that creates two-way binding on the editor's value (for example, TextBox value):

<dx-text-box v-model="text" />

Custom Templates

You can customize widget elements' appearance via the corresponding template properties.

To specify a DevExtreme Vue Component template, use a named slot to specify a template's markup. You also should specify a slot scope to access the template element's data.

For instance, you can specify the itemTemplate:

<div id="app">
    <dx-list :items="items">
        <div slot="item" slot-scope="data">
            <i>This is my template for {{data}}</i>
        </div>
    </dx-list>
</div>
import Vue from 'vue';
import { DxList } from 'devextreme-vue';

new Vue({
  el: '#app',
  components: { DxList },
  data() {
    return {
      items: [1, 2, 3, 4]
    };
  }
});

item is the default template name of the dxList widget's itemTemplate option. You can specify a custom name for the itemTemplate option and for your slot:

<div id="app">
    <dx-list :items="items" item-template="my-template">
        <div slot="my-template" slot-scope="data">
            <i>This is my template for {{data}}</i>
        </div>
    </dx-list>
</div>

Components with Transcluded Content

In addition to using templates, you can put the following widgets' content directly into the markup: Resizable, ScrollView, ValidationGroup. For instance, you can specify the ScrollView widget's content as follows:

<dx-scroll-view>
    <div>Some scrollable content</div>
</dx-scroll-view>

Event Handling

You can subscribe to DevExtreme Component Events using the Vue's v-on directive (or @ shorthand)

<dx-text-box v-model="text" @focusIn="handleFocusIn'" />
data: function() {
  return {
    text: "text",
    handleFocusIn: () => {
      this.text = 'focused!';
    }
  };
}

You can find the full list of component events in each DevExtreme widget API Reference's Events section (for example, TextBox events).

Getting a Widget Instance

A widget instance is used when calling a widget method. You can get it in the following way: 1. Assign a unique key to the component's ref attribute. 1. Use this key to retrieve the component from the $refs property. 1. Use the component's instance property to get the widget instance.

<template>
    <div title="Accessing Widget Instance">
        <dx-text-box :ref="textBoxRefName"/>
        <br/>
        <dx-button text="Set focus" @click="setFocus"/>
    </div>
</template>

<script>
import { DxButton, DxTextBox } from "devextreme-vue";

const textBoxRefName = "some-ref-name";

export default {
  data: function() {
    return {
      textBoxRefName
    };
  },

  components: {
    DxTextBox,
    DxButton
  },

  methods: {
    setFocus: function() {
      this.textBox.focus();
    }
  },

  computed: {
    textBox: function() {
      return this.$refs[textBoxRefName].instance;
    }
  }
};
</script>

Type Checks

You should specify proper values for the components' properties because DevExtreme Vue components use Prop Validation and Type Checks. Otherwise, Vue produces a console warning (if you are using the development build).

DevExtreme Data Layer and Utils

The DevExtreme includes a Data Layer and Utils that can be helpful in different scenarios.

DevExtreme Validation

DevExtreme Vue editors support built-in data validation.

<dx-validation-group>
  <dx-text-box value="email@mail.com">
    <dx-validator :validationRules="validationRules.email" />
  </dx-text-box>
  <dx-text-box value="password">
    <dx-validator :validationRules="validationRules.password" />
  </dx-text-box>
  <dx-validation-summary />
  <dx-button text="Submit" @click="validate"/>
</dx-validation-group>
import { DxButton, DxTextBox, DxValidator, DxValidationGroup, DxValidationSummary } from "devextreme-vue";

export default {
  components: {
    DxButton,
    DxTextBox, 
    DxValidator,
    DxValidationGroup,
    DxValidationSummary
  },
  methods: {
    validate(params) {
      const result = params.validationGroup.validate();
      if (result.isValid) {
          // form data is valid
          //params.validationGroup.reset();
      }     
    }
  },
  data: function() {
    return {
      validationRules: {
        email: [
            { type: "required", message: "Email is required." },
            { type: "email", message: "Email is invalid." }
        ],
        password: [
            { type: "required", message: "Password is required." }
        ]
    }};
  }
};

License

DevExtreme Vue components are released as an MIT-licensed (free and open-source) DevExtreme add-on.

See the DevExtreme License for more information.

A free trial is available

Support & Feedback

23.1.9

2 months ago

23.2.5

2 months ago

22.1.13

3 months ago

22.2.11

3 months ago

23.1.8

3 months ago

23.2.4

3 months ago

22.1.12

5 months ago

23.1.7

5 months ago

22.2.10

5 months ago

21.2.15

5 months ago

23.2.3

5 months ago

22.1.11

8 months ago

23.2.2-beta

6 months ago

22.2.9

7 months ago

22.2.8

8 months ago

23.1.5

8 months ago

23.1.4

10 months ago

23.1.6

7 months ago

22.1.10

10 months ago

22.2.7

10 months ago

21.2.14

10 months ago

23.1.3

11 months ago

23.1.2-beta

11 months ago

23.1.2-beta.2

11 months ago

22.1.9

1 year ago

22.2.6

1 year ago

20.1.17

1 year ago

20.2.13

1 year ago

21.2.13

1 year ago

21.1.12

1 year ago

22.2.5

1 year ago

22.1.8

1 year ago

22.1.7

1 year ago

22.2.4

1 year ago

22.2.3

1 year ago

21.2.12

1 year ago

20.1.16

2 years ago

22.2.2-beta

1 year ago

22.1.6

2 years ago

19.1.16

2 years ago

21.2.11

2 years ago

19.2.15

2 years ago

18.2.18

2 years ago

21.1.11

2 years ago

20.2.12

2 years ago

22.1.5

2 years ago

21.2.10

2 years ago

21.2.9

2 years ago

22.1.4

2 years ago

22.1.3

2 years ago

21.1.10

2 years ago

21.2.8

2 years ago

22.1.2-beta

2 years ago

20.1.15

2 years ago

21.1.9

2 years ago

21.2.7

2 years ago

19.1.15

2 years ago

19.2.14

2 years ago

18.2.17

2 years ago

20.2.11

2 years ago

21.2.6

2 years ago

20.1.14

2 years ago

21.1.8

2 years ago

21.1.7

2 years ago

21.2.4

2 years ago

21.2.5

2 years ago

19.1.14

2 years ago

19.2.13

2 years ago

18.2.16

2 years ago

20.2.10

2 years ago

21.2.3

3 years ago

21.2.2-beta

3 years ago

21.1.6

3 years ago

20.2.9

3 years ago

21.1.5

3 years ago

20.1.13

3 years ago

20.2.8

3 years ago

21.1.4

3 years ago

21.1.3

3 years ago

20.1.12

3 years ago

20.2.7

3 years ago

19.1.13

3 years ago

19.2.12

3 years ago

18.2.15

3 years ago

21.1.2-beta

3 years ago

20.1.11

3 years ago

20.2.6

3 years ago

20.1.10

3 years ago

20.2.5

3 years ago

19.2.11

3 years ago

20.2.4

3 years ago

20.1.9

3 years ago

20.2.3

4 years ago

20.1.8

4 years ago

19.2.10

4 years ago

19.1.12

4 years ago

18.2.14

4 years ago

20.2.2-beta

4 years ago

20.1.7

4 years ago

20.1.6

4 years ago

20.1.5

4 years ago

19.2.9

4 years ago

20.1.4

4 years ago

18.2.13

4 years ago

19.2.8

4 years ago

19.1.11

4 years ago

20.1.3

4 years ago

20.1.2-beta

4 years ago

19.1.10

4 years ago

18.2.12

4 years ago

19.2.7

4 years ago

19.2.6

4 years ago

19.1.9

4 years ago

19.2.5

4 years ago

19.2.4

4 years ago

19.1.8

4 years ago

18.2.11

4 years ago

19.2.3

5 years ago

19.1.7

5 years ago

19.2.2-beta

5 years ago

19.1.6

5 years ago

18.2.10

5 years ago

19.1.5

5 years ago

19.1.4

5 years ago

18.2.9

5 years ago

18.2.9-pre-19149

5 years ago

19.1.3

5 years ago

18.2.9-pre-19135

5 years ago

18.2.9-pre-19128

5 years ago

18.2.8

5 years ago

19.1.2-beta

5 years ago

18.2.8-pre-19107

5 years ago

18.2.8-pre-19091

5 years ago

18.2.8-pre-19081

5 years ago

18.2.8-pre-19080

5 years ago

18.2.8-pre-19082

5 years ago

18.2.7

5 years ago

18.2.6

5 years ago

18.2.5

5 years ago

18.2.4

5 years ago

18.2.4-beta.1

5 years ago

18.2.3

5 years ago

18.2.2-beta.1

6 years ago

18.1.7-alpha.10

6 years ago

18.1.6-alpha.9

6 years ago

18.2.1-alpha.1

6 years ago

18.1.5-alpha.8

6 years ago

18.1.4-alpha.7

6 years ago

18.1.4-alpha.6

6 years ago

18.1.4-alpha.5

6 years ago

18.1.3-alpha.4

6 years ago

18.1.2-alpha.3

6 years ago

18.1.1-alpha.2

6 years ago

18.1.1-alpha.1

6 years ago