Cascader support slot

Cascader support slot
This commit is contained in:
梁灏 2017-01-16 17:46:51 +08:00
parent 54a83aa565
commit 75e5c6a51e
3 changed files with 78 additions and 69 deletions

View file

@ -1,14 +1,17 @@
<template> <template>
<div :class="classes" v-clickoutside="handleClose"> <div :class="classes" v-clickoutside="handleClose">
<div :class="[prefixCls + '-rel']" @click="toggleOpen">
<slot>
<i-input <i-input
readonly readonly
:disabled="disabled" :disabled="disabled"
:value.sync="displayRender" :value.sync="displayRender"
:size="size" :size="size"
:placeholder="placeholder" :placeholder="placeholder"></i-input>
@on-focus="onFocus"></i-input>
<Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.stop="clearSelect"></Icon> <Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.stop="clearSelect"></Icon>
<Icon type="arrow-down-b" :class="[prefixCls + '-arrow']"></Icon> <Icon type="arrow-down-b" :class="[prefixCls + '-arrow']"></Icon>
</slot>
</div>
<Dropdown v-show="visible" transition="slide-up"> <Dropdown v-show="visible" transition="slide-up">
<div> <div>
<Caspanel <Caspanel
@ -125,6 +128,13 @@
handleClose () { handleClose () {
this.visible = false; this.visible = false;
}, },
toggleOpen () {
if (this.visible) {
this.handleClose();
} else {
this.onFocus();
}
},
onFocus () { onFocus () {
this.visible = true; this.visible = true;
if (!this.value.length) { if (!this.value.length) {

View file

@ -2,9 +2,13 @@
@cascader-item-prefix-cls: ~"@{css-prefix}cascader-menu-item"; @cascader-item-prefix-cls: ~"@{css-prefix}cascader-menu-item";
.@{cascader-prefix-cls} { .@{cascader-prefix-cls} {
position: relative; //position: relative;
line-height: normal; line-height: normal;
&-rel{
position: relative;
}
.@{css-prefix}input{ .@{css-prefix}input{
display: block; display: block;
cursor: pointer; cursor: pointer;

View file

@ -1,18 +1,15 @@
<template> <template>
<Cascader :data="data" :value.sync="value" change-on-select></Cascader> {{ text }}
<Cascader :data="data" @on-change="handleChange">
<a href="javascript:void(0)">选择</a>
</Cascader>
</template> </template>
<script> <script>
export default { export default {
data () { data () {
return { return {
value: [], text: '未选择',
data: [] data: [{
}
},
methods: {
updateData () {
setTimeout(() => {
this.data = [{
value: 'beijing', value: 'beijing',
label: '北京', label: '北京',
children: [ children: [
@ -39,7 +36,7 @@
children: [ children: [
{ {
value: 'fuzimiao', value: 'fuzimiao',
label: '夫子庙' label: '夫子庙',
} }
] ]
}, },
@ -49,24 +46,22 @@
children: [ children: [
{ {
value: 'zhuozhengyuan', value: 'zhuozhengyuan',
label: '拙政园' label: '拙政园',
}, },
{ {
value: 'shizilin', value: 'shizilin',
label: '狮子林' label: '狮子林',
} }
] ]
} }
] ],
}]; }]
setTimeout(() => {
this.value = ['beijing', 'tiantan'];
}, 1000);
}, 1000);
} }
}, },
ready () { methods: {
this.updateData(); handleChange (value, selectedData) {
this.text = selectedData.map(o => o.label).join(', ');
}
} }
} }
</script> </script>