除了支持 通用属性 以外,还支持如下属性。
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
selected |
boolean |
- |
否 |
选择项是否为下拉列表的默认项。 |
value |
string |
- |
是 |
选择项的值,展示的值放在标签内,例如<option value="volvo">Volvo XC90</option>。 |
除了支持 通用样式 以外,还支持如下样式。
option不支持自定义宽度和高度,即对width和height设置无效。option的宽度跟随select的宽度,高度是固定不变的。
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
color |
color |
0x8a000000 |
否 |
文本颜色。 |
font-size |
number |
30px |
否 |
文本尺寸。 |
font-weight |
lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | normal | bold | bolder |
normal |
否 |
字体的粗细,默认为normal。 |
text-decoration |
underline | line-through | none |
none |
否 |
添加到文本的修饰。 |
font-family(1030+) |
string |
- |
否 |
通过该属性可以设置组件中字符串的字体,支持四种系统原生字体:normal,sans-serif,serif,monospace(此四种字体只对英文有效)。 如果需要设置自定义字体,请参见“font-face样式”。 |
<template>
<div class="container container1">
<div class="page-title-wrap">
<text class="page-title">{{componentName}}</text>
</div>
<div class="item-container">
<text style="margin-bottom: 50px">Nanjing Attractions</text>
<select class="select" onchange="changeValue">
<option class="option" value="item1">Confucius Temple</option>
<option class="optionrgb" value="item2" selected="true">presidential palace</option>
<option class="optionrgba" value="item3">Old door east</option>
<option class="optionhsl" value="item4">Da Bao En Temple</option>
<option class="optionhsla" value="item5">Zhonghuamen</option>
</select>
</div>
<div class="item-container">
<text style="margin-bottom: 50px">font-family</text>
<select class="select font-family2" onchange="changeValue">
<option class="option font-family1" value="item1">font-family is sans-serif</option>
<option class="option font-family2" value="item2" selected="true">font-family is serif</option>
<option class="option font-family3" value="item3">font-family is monospace</option>
</select>
</div>
</div>
</template>
<style>
.container {
flex: 1;
flex-direction: column;
}
.page-title-wrap {
padding-top: 50px;
padding-bottom: 80px;
justify-content: center;
}
.page-title {
padding-top: 30px;
padding-bottom: 30px;
padding-left: 40px;
padding-right: 40px;
border-color: #bbbbbb;
color: #bbbbbb;
border-bottom-width: 2px;
}
.item-container {
margin-bottom: 50px;
margin-right: 60px;
margin-left: 60px;
flex-direction: column;
}
.select {
margin-left: 30px;
margin-right: 30px;
align-items: flex-start;
border-color: #007DFF;
border-width: 1px;
}
.container1 {
align-items: center;
}
.option {
color: #007DFF;
font-size: 30px;
font-weight: bold;
text-decoration: line-through;
}
.optionrgb {
color: rgb(207, 18, 49);
font-size: 30px;
font-weight: bold;
text-decoration: line-through;
}
.optionrgba {
color: rgba(86, 206, 38, 0.452);
font-size: 30px;
font-weight: bold;
text-decoration: line-through;
}
.optionhsl {
color: hsl(180, 100%, 80%);
font-size: 30px;
font-weight: bold;
text-decoration: line-through;
}
.optionhsla {
color: hsla(10, 90%, 60%, 0.9);
font-size: 30px;
font-weight: bold;
text-decoration: line-through;
}
.font-family1 {
font-family: sans-serif;
}
.font-family2 {
font-family: serif;
}
.font-family3 {
font-family: monospace;
}
</style>
<script>
import prompt from '@system.prompt'
export default {
data: {
componentName: 'select'
},
onInit() {
this.$page.setTitleBar({ text: 'option' })
},
changeValue(e) {
prompt.showToast({
message: `[${e.newValue}] selected`,
duration: 2000,
gravity: 'center'
})
}
}
</script>
效果图如下:
