基本用法
data() {
return {
selected: '',
options: ['Option1', 'Option2']
}
}
}
options 为选项数组,默认不选中任何的选项,点击其中一个,则对应的 selected 的值就为选中项的值。
设置 value,禁用状态,图标样式
export default {
data() {
return {
selected2: 3,
options2: [
{
label: 'Option1',
value: 1
},
{
label: 'Option2',
value: 2
},
label: 'Option3',
value: 3,
disabled: true
}
}
}
}
设置 position 为 ‘right’,则单选框图标位置在右边。设置 hollow-style 为 true 则使用镂空样式。
水平排列
export default {
data() {
return {
selected3: '3',
options3: [
{
label: '1',
value: '1'
},
{
label: '2',
value: '2'
},
{
label: '3',
value: '3',
disabled: true
}
]
}
}
使用默认插槽
data() {
return {
selected4: '1',
options4: [
{
label: '1',
value: '1',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1516805611092&di=80d0f229dd999ffa3be79d6e317832b0&imgtype=0&src=http%3A%2F%2Fimglf0.ph.126.net%2F1EnYPI5Vzo2fCkyy2GsJKg%3D%3D%2F2829667940890114965.jpg'
},
{
label: '2',
value: '2',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1516805611092&di=80d0f229dd999ffa3be79d6e317832b0&imgtype=0&src=http%3A%2F%2Fimglf0.ph.126.net%2F1EnYPI5Vzo2fCkyy2GsJKg%3D%3D%2F2829667940890114965.jpg'
},
{
label: '3',
value: '3',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1516805611092&di=80d0f229dd999ffa3be79d6e317832b0&imgtype=0&src=http%3A%2F%2Fimglf0.ph.126.net%2F1EnYPI5Vzo2fCkyy2GsJKg%3D%3D%2F2829667940890114965.jpg',
disabled: true
}
]
}
}
}
- options 子配置项
注:如果 options
中的项为字符串也是可以的,此时默认 和 value
的值都为该字符串的值。
- option 子配置项