Using kintone UI Component v1 in Vue #991
Replies: 1 comment
-
OverviewAs we wrote in the main text, there is a version conflict issue when defining multiple kintone UI Component (KUC) packages on custom JS/plug-in at the same time. When importing multiple KUC packages (ESM) and using custom HTML tags directly:For example, we have two scripts that are packaged by webpack as follows.
We can see that the text color of Dropdown in the v1.3.1 script is overridden by v1.2.0 script. You can refer to the Version conflicts issue and solution for the issue detail. This issue is solved in KUC v1.4.0.From v1.4.0, you need to write with version number included tag like In addition, class names have also been changed to avoid CSS style conflicts. There is some sample code for reference. Sample codeAssuming you are currently using KUC v1.4.0 in your project, you can refer to the following sample code.
<template>
<div class="text-sample">
<kuc-button-1-4-0
:text="count"
@click="updateCount"
/>
<kuc-text-1-4-0
className="kuc-text-ui"
:label="label"
:error="error"
:hidden="hidden"
@change="handleChange"
/>
</div>
</template>
<script>
import "kintone-ui-component";
export default {
data() {
return {
label: "",
error: "",
hidden: null,
count: 0,
value: "",
};
},
methods: {
updateCount() {
this.count += 1;
this.error = this.count % 2 === 0 ? "" : this.count;
this.label = this.count.toString();
},
handleChange(event) {
console.log(event);
this.value = event.detail.value;
},
},
};
</script>
<style scoped>
.text-sample {
display: inline-flex
}
</style>
<template>
<div>
<kuc-notification-1-4-0
ref="kucNotification"
text="Notification"
type="info"
@close="handleClose"
/>
<kuc-button-1-4-0
text="Open Notification"
@click="openNotification"
/>
<kuc-button-1-4-0
text="Close Notification"
@click="closeNotification"
/>
</div>
</template>
<script>
import "kintone-ui-component";
export default {
methods: {
handleClose(event) {
console.log(event);
},
openNotification() {
this.$refs.kucNotification.open();
},
closeNotification() {
this.$refs.kucNotification.close();
}
},
}
</script> In order to avoid modifying too much code after future upgrades, you can use the version function to generate the suffix of the tag.
<template>
<div style="display:flex">
{{version}}
<component
:is="`kuc-button${generateVersionSuffix(version)}`"
text="Show text value"
type="submit"
@click="label = value"
/>
<component
:is="`kuc-text${generateVersionSuffix(version)}`"
:label="label"
@change="handleChange"
/>
</div>
</template>
<script>
import { version } from "kintone-ui-component";
export default {
data() {
return {
label: "",
value: "",
version
};
},
methods: {
handleChange(event) {
this.value = event.detail.value;
},
generateVersionSuffix(v) {
return `-${v.replace(/\./g, "-")}`;
}
},
};
</script> |
Beta Was this translation helpful? Give feedback.
-
Background
Some developers want to use kintone UI Component (KUC) v1 in their Vue project.
But now, we don't provide Vue version and don't have a plan to support it officially in the future.
Internally we are using Web Components so that developers can access it from Vue.
https://vuejs.org/guide/extras/web-components.html#vue-and-web-components
So as an option for Vue users, we want to share the possible coding way with it.
Here is an unofficial guide on how to use KUC v1 in Vue.
Unofficial means that we don't test the behavior and support it.
Note for Coding
We are not supporting Vue coding way officially now, so please develop on your own responsibility.
Currently, there is a version conflict issue when defining multiple KUC packages (both same version and different version) on custom JS/plug-in at the same time.
Using tag directly like Vue, the first loaded KUC version will be used.
So we are working on solving the issue now and note that there is a possibility that you need to write with version number included tag like <kuc-button-1-3-0> in the near future.
Guide
Developer needs to write in different way depending on the property type, event and method of KUC.
We created some sample codes for property type, event and method.
These samples are authored in "Options API" styles.
You can refer to them.
KUC is using custom element, so you can specify the "compilerOptions.isCustomElement" option to exclude it from component resolution.
https://vuejs.org/guide/extras/web-components.html#using-custom-elements-in-vue
e.g. Using "vue-loader" in webpack.config.js
KUC component properties
String type property
This type property can be set like an HTML Attribute.
For example, "type" and "text" of Button component.
In this case, the static value can be passed.
It also can be set dynamically with v-bind directive. (: is the shorthand)
Pay attention to the name of property and its reflecting attribute.
property is "className", attribute is "class"
property is "visible", attribute is "hidden"
Note: only the property with the setting "reflect: true" have the reflecting attribute, not all.
So please be careful if you use setAttribute and getAttribute.
Sample code
<kuc-button text="Show text value" type="submit" className="kuc-button" />
Boolean, Array, Number or HTMLElement type property
These properties can be set with v-bind directive.
We can call a function to change the value dynamically.
For example, "requiredIcon" and "items" of Dropdown component, "duration" of Notification component, "content" and "footer" of Dialog component.
About how to create a HTMLElement in Vue, you can refer to the following steps.
(1) Creating a HTMLElement by document.createElement().
(2) Using createApp() to create an application instance and mount() to mount in this HTMLElement.
Then you can set this HTMLElement as "content" or "footer".
Sample code
A sample of Dropdown component
A sample of Dialog component
Export a function to handle text change. So the value of text can be used in the main file.
Export a function to handle button clicking.
In mounted lifecycle function, creating HTMLElement for setting "content" and "footer".
KUC component event
Sample code
KUC component method
e.g. this.$refs.kucNotification.open();
Sample code
Beta Was this translation helpful? Give feedback.
All reactions