翻譯|使用教程|編輯:龔雪|2022-08-10 10:12:23.820|閱讀 234 次
概述:本文主要為大家介紹如何使用Kendo UI for Vue的來設置按鈕的外觀,歡迎下載最新版控件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Kendo UI for Vue原生組件——Button 提供了一組預定義的外觀選項。除了 Button 的默認外觀之外,這些替代樣式選項使您能夠配置組件外觀的每個單獨方面。
本文將提供有關在應用其屬性的不同配置時組件如何更改的詳細信息。
以下示例演示如何通過配置器配置 Button 外觀的不同方面。
main.vue
<template>
<div>
<ButtonsStyleConfigurator
:shape="shape"
@shapechange="setShape"
:size="size"
@sizechange="setSize"
:theme-color="themeColor"
@themecolorchange="setThemeColor"
:fill-mode="fillMode"
@fillmodechange="setFillMode"
:rounded="rounded"
@roundedchange="setRounded"
/>
<kbutton
:shape="shape"
:size="size"
:theme-color="themeColor"
:fill-mode="fillMode"
:rounded="rounded"
>
Button
</kbutton>
</div>
</template>
<script>
import { Button } from "@progress/kendo-vue-buttons";
import ButtonStyleConfigurator from "./ButtonStyleConfigurator";
export default {
components: {
ButtonStyleConfigurator,
"kbutton": Button,
},
data() {
return {
shape: "rectangle",
size: "medium",
themeColor: "base",
fillMode: "solid",
rounded: "medium",
};
},
methods: {
setShape(shape) {
this.shape = shape;
},
setSize(event) {
this.size = event.value;
},
setThemeColor(event) {
this.themeColor = event.value
},
setFillMode(event) {
this.fillMode = event.value
},
setRounded(event) {
this.rounded = event.value
},
},
};
</script>
main.js
import { createApp } from 'vue'
import App from './main.vue'
createApp(App).mount('#app')
ButtonStyleConfigurator.vue
<template>
<div :style="{ margin: '-30px -30px 30px -30px' }">
<div :style="{ display: 'flex', justifyContent: 'center' }">
<span
class="k-color-primary"
:style="{ textTransform: 'uppercase', padding: '4px 0' }"
>Configurator</span
>
</div>
<div
class="example-config"
:style="{
display: 'flex',
justifyContent: 'space-between',
flexWrap: 'wrap',
}"
>
<span v-if="shape !== undefined" class="k-form-field">
<k-label>
Shape
<div class="k-form-field-wrap">
<kbuttongroup>
<kbutton
v-for="(shapeElelement, index) in shapes"
:key="index"
:togglable="true"
:selected="shapeElelement === shape"
@click="handleShapeChange(shapeElelement)"
>
{{ shapeElelement || "None" }}
</kbutton>
</kbuttongroup>
</div>
</k-label>
</span>
<span class="k-form-field">
<k-label>
Size
<div class="k-form-field-wrap">
<dropdownlist
:data-items="sizes"
:value="size"
:style="{
'min-width': '120px',
}"
@change="handleSizeChange"
/>
</div>
</k-label>
</span>
<span class="k-form-field">
<k-label>
Theme Color
<div class="k-form-field-wrap">
<dropdownlist
:data-items="themeColors"
:value="themeColor"
:item-render="'colorItemRender'"
:style="{
'min-width': '150px',
}"
@change="handleThemeColorChange"
>
<template v-slot:colorItemRender="{ props }">
<li
:class="props.itemClass"
@click="(ev) => props.onClick(ev)"
:style="{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}"
>
{{ props.dataItem }}{{ ' ' }}
<span
:style="{
width: '16px',
height: '16px',
background: 'currentColor',
display: 'inline-block',
}"
:class="['k-color-' + props.dataItem]"
></span>
</li>
</template>
</dropdownlist>
</div>
</k-label>
</span>
<span class="k-form-field">
<k-label>
Fill Mode
<div class="k-form-field-wrap">
<dropdownlist
:data-items="fillModes"
:value="fillMode"
:style="{
'min-width': '120px',
}"
@change="handleFillModeChange"
/>
</div>
</k-label>
</span>
<span class="k-form-field">
<k-label>
Border Radius
<div class="k-form-field-wrap">
<dropdownlist
:data-items="roundedOptions"
:value="rounded"
:style="{
'min-width': '120px',
}"
@change="handleRoundedChange"
/>
</div>
</k-label>
</span>
</div>
</div>
</template>
<script>
import { Label } from "@progress/kendo-vue-labels";
import { ButtonGroup, Button } from "@progress/kendo-vue-buttons";
import { DropDownList } from "@progress/kendo-vue-dropdowns";
export default {
components: {
"k-label": Label,
"kbutton": Button,
"k-buttongroup": ButtonGroup,
dropdownlist: DropDownList,
},
props: {
shape: String,
size: String,
themeColor: String,
fillMode: String,
rounded: String,
},
emits: [
"shapechange",
"sizechange",
"themecolorchange",
"fillmodechange",
"roundedchange",
],
data() {
return {
shapes: ["rectangle", "square"],
sizes: ["small", "medium", "large"],
themeColors: [
"base",
"primary",
"secondary",
"tertiary",
"info",
"success",
"warning",
"error",
"dark",
"light",
"inverse",
],
fillModes: ["solid", "outline", "flat", "clear", "link"],
roundedOptions: ["small", "medium", "large", "full"],
};
},
methods: {
handleShapeChange(shape) {
this.$emit("shapechange", shape);
},
handleSizeChange(event) {
this.$emit("sizechange", event);
},
handleThemeColorChange(event) {
this.$emit("themecolorchange", event);
},
handleFillModeChange(event) {
this.$emit("fillmodechange", event);
},
handleRoundedChange(event) {
this.$emit("roundedchange", event);
},
},
};
</script>
Button 的大小是通過其 size 屬性控制的,可以傳遞給屬性的值如下:
以下示例演示了每個大小選項的用法:
main.vue
<template>
<div>
<span class="wrapper">
<kbutton :size="'small'">Small Size</kbutton>
</span>
<span class="wrapper">
<kbutton :size="'medium'">Medium Size</kbutton>
</span>
<span class="wrapper">
<kbutton :size="'large'">Large Size</kbutton>
</span>
<span class="wrapper">
<kbutton :size="null" :class="'custom-size'">Custom Size</kbutton>
</span>
</div>
</template>
<script>
import { Button } from '@progress/kendo-vue-buttons';
export default {
components: {
kbutton: Button,
}
};
</script>
<style>
.custom-size.k-button {
padding: 20px 20px;
}
.wrapper {
padding: 20px;
}
</style>
main.js
import { createApp } from 'vue'
import App from './main.vue'
createApp(App).mount('#app')
Button 的形狀通過其 shape 屬性進行控制,可以傳遞給屬性的值如下:
以下示例演示了每個形狀選項的用法:
main.vue
<template>
<div>
<span class="wrapper">
<kbutton :shape="'rectangle'">Rectangle shape</kbutton>
</span>
<span class="wrapper">
<kbutton :shape="'square'">Square shape</kbutton>
</span>
</div>
</template>
<script>
import { Button } from '@progress/kendo-vue-buttons';
export default {
components: {
kbutton: Button,
},
};
</script>
<style>
.wrapper {
padding: 20px;
}
</style>
main.js
import { createApp } from 'vue'
import App from './main.vue'
createApp(App).mount('#app')
Kendo UI致力于新的開發,來滿足不斷變化的需求。Kendo UI for Vue使用旨在提高性能和豐富用戶體驗的Vue組件,幫助開發人員構建下一代應用程序。它是為Vue技術框架提供可用的Kendo UI組件,以便更快地構建更好的Vue應用程序。
Telerik_KendoUI產品技術交流群:726377843 歡迎一起進群討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉載自:慧都網