默认选中

使用selected属性

当然selected是选中, disabled是禁用

<div id="demo2" class="xm-select-demo"></div>

<script>
var demo2 = xmSelect.render({
	el: '#demo2', 
	data: [
		{name: '水果', value: 1, selected: true, disabled: true},
		{name: '蔬菜', value: 2, selected: true},
		{name: '桌子', value: 3, disabled: true},
		{name: '北京', value: 4},
	]
})
</script>

使用initValue进行初始化

initValue的优先级大于选项中的selected

<div id="demo1" class="xm-select-demo"></div>

<script>
var demo5 = xmSelect.render({
	el: '#demo1', 
	initValue: [4],
	data: [
		{name: '水果', value: 1, selected: true, disabled: true},
		{name: '蔬菜', value: 2, selected: true},
		{name: '桌子', value: 3, disabled: true},
		{name: '北京', value: 4},
	]
})
</script>
上次更新:
贡献者: leedom