Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
devextreme-vue
Advanced tools
This project allows you to use DevExtreme Widgets as Vue Components.
You can try this live example (no need to install anything).
See the sections below if you prefer using a local development environment.
Node.js and npm are required
Install the devextreme and devextreme-vue npm packages:
npm install --save devextreme@18.1 devextreme-vue
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.
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!'
};
}
});
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.
<dx-button text="Simple button" />
<dx-check-box :value="true" />
<dx-button :text="text" />
where :
is a shorthand for v-bind
directive.
Use the sync
modifier to bind a bindingProperty
to a widget option:
<dx-text-box :value.sync="bindingProperty" />
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" />
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 can 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>
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>
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).
A widget instance is used when calling a widget method. You can get it in the following way:
ref
attribute.$refs
property.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>
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).
The DevExtreme includes a Data Layer and Utils that can be helpful in different scenarios.
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." }
]
}};
}
};
DevExtreme Vue components are released as an MIT-licensed (free and open-source) DevExtreme add-on.
See the DevExtreme License for more information.
FAQs
DevExtreme Vue UI and Visualization Components
The npm package devextreme-vue receives a total of 13,496 weekly downloads. As such, devextreme-vue popularity was classified as popular.
We found that devextreme-vue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.