Commit 75e5c6a51ea070a2c9d40ddae18267f48c409be9
1 parent
54a83aa5
Cascader support slot
Cascader support slot
Showing
3 changed files
with
78 additions
and
69 deletions
Show diff stats
src/components/cascader/cascader.vue
| 1 | 1 | <template> |
| 2 | 2 | <div :class="classes" v-clickoutside="handleClose"> |
| 3 | - <i-input | |
| 4 | - readonly | |
| 5 | - :disabled="disabled" | |
| 6 | - :value.sync="displayRender" | |
| 7 | - :size="size" | |
| 8 | - :placeholder="placeholder" | |
| 9 | - @on-focus="onFocus"></i-input> | |
| 10 | - <Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.stop="clearSelect"></Icon> | |
| 11 | - <Icon type="arrow-down-b" :class="[prefixCls + '-arrow']"></Icon> | |
| 3 | + <div :class="[prefixCls + '-rel']" @click="toggleOpen"> | |
| 4 | + <slot> | |
| 5 | + <i-input | |
| 6 | + readonly | |
| 7 | + :disabled="disabled" | |
| 8 | + :value.sync="displayRender" | |
| 9 | + :size="size" | |
| 10 | + :placeholder="placeholder"></i-input> | |
| 11 | + <Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.stop="clearSelect"></Icon> | |
| 12 | + <Icon type="arrow-down-b" :class="[prefixCls + '-arrow']"></Icon> | |
| 13 | + </slot> | |
| 14 | + </div> | |
| 12 | 15 | <Dropdown v-show="visible" transition="slide-up"> |
| 13 | 16 | <div> |
| 14 | 17 | <Caspanel |
| ... | ... | @@ -125,6 +128,13 @@ |
| 125 | 128 | handleClose () { |
| 126 | 129 | this.visible = false; |
| 127 | 130 | }, |
| 131 | + toggleOpen () { | |
| 132 | + if (this.visible) { | |
| 133 | + this.handleClose(); | |
| 134 | + } else { | |
| 135 | + this.onFocus(); | |
| 136 | + } | |
| 137 | + }, | |
| 128 | 138 | onFocus () { |
| 129 | 139 | this.visible = true; |
| 130 | 140 | if (!this.value.length) { | ... | ... |
src/styles/components/cascader.less
| ... | ... | @@ -2,9 +2,13 @@ |
| 2 | 2 | @cascader-item-prefix-cls: ~"@{css-prefix}cascader-menu-item"; |
| 3 | 3 | |
| 4 | 4 | .@{cascader-prefix-cls} { |
| 5 | - position: relative; | |
| 5 | + //position: relative; | |
| 6 | 6 | line-height: normal; |
| 7 | 7 | |
| 8 | + &-rel{ | |
| 9 | + position: relative; | |
| 10 | + } | |
| 11 | + | |
| 8 | 12 | .@{css-prefix}input{ |
| 9 | 13 | display: block; |
| 10 | 14 | cursor: pointer; | ... | ... |
test/routers/cascader.vue
| 1 | 1 | <template> |
| 2 | - <Cascader :data="data" :value.sync="value" change-on-select></Cascader> | |
| 2 | + {{ text }} | |
| 3 | + <Cascader :data="data" @on-change="handleChange"> | |
| 4 | + <a href="javascript:void(0)">选择</a> | |
| 5 | + </Cascader> | |
| 3 | 6 | </template> |
| 4 | 7 | <script> |
| 5 | 8 | export default { |
| 6 | 9 | data () { |
| 7 | 10 | return { |
| 8 | - value: [], | |
| 9 | - data: [] | |
| 11 | + text: '未选择', | |
| 12 | + data: [{ | |
| 13 | + value: 'beijing', | |
| 14 | + label: '北京', | |
| 15 | + children: [ | |
| 16 | + { | |
| 17 | + value: 'gugong', | |
| 18 | + label: '故宫' | |
| 19 | + }, | |
| 20 | + { | |
| 21 | + value: 'tiantan', | |
| 22 | + label: '天坛' | |
| 23 | + }, | |
| 24 | + { | |
| 25 | + value: 'wangfujing', | |
| 26 | + label: '王府井' | |
| 27 | + } | |
| 28 | + ] | |
| 29 | + }, { | |
| 30 | + value: 'jiangsu', | |
| 31 | + label: '江苏', | |
| 32 | + children: [ | |
| 33 | + { | |
| 34 | + value: 'nanjing', | |
| 35 | + label: '南京', | |
| 36 | + children: [ | |
| 37 | + { | |
| 38 | + value: 'fuzimiao', | |
| 39 | + label: '夫子庙', | |
| 40 | + } | |
| 41 | + ] | |
| 42 | + }, | |
| 43 | + { | |
| 44 | + value: 'suzhou', | |
| 45 | + label: '苏州', | |
| 46 | + children: [ | |
| 47 | + { | |
| 48 | + value: 'zhuozhengyuan', | |
| 49 | + label: '拙政园', | |
| 50 | + }, | |
| 51 | + { | |
| 52 | + value: 'shizilin', | |
| 53 | + label: '狮子林', | |
| 54 | + } | |
| 55 | + ] | |
| 56 | + } | |
| 57 | + ], | |
| 58 | + }] | |
| 10 | 59 | } |
| 11 | 60 | }, |
| 12 | 61 | methods: { |
| 13 | - updateData () { | |
| 14 | - setTimeout(() => { | |
| 15 | - this.data = [{ | |
| 16 | - value: 'beijing', | |
| 17 | - label: '北京', | |
| 18 | - children: [ | |
| 19 | - { | |
| 20 | - value: 'gugong', | |
| 21 | - label: '故宫' | |
| 22 | - }, | |
| 23 | - { | |
| 24 | - value: 'tiantan', | |
| 25 | - label: '天坛' | |
| 26 | - }, | |
| 27 | - { | |
| 28 | - value: 'wangfujing', | |
| 29 | - label: '王府井' | |
| 30 | - } | |
| 31 | - ] | |
| 32 | - }, { | |
| 33 | - value: 'jiangsu', | |
| 34 | - label: '江苏', | |
| 35 | - children: [ | |
| 36 | - { | |
| 37 | - value: 'nanjing', | |
| 38 | - label: '南京', | |
| 39 | - children: [ | |
| 40 | - { | |
| 41 | - value: 'fuzimiao', | |
| 42 | - label: '夫子庙' | |
| 43 | - } | |
| 44 | - ] | |
| 45 | - }, | |
| 46 | - { | |
| 47 | - value: 'suzhou', | |
| 48 | - label: '苏州', | |
| 49 | - children: [ | |
| 50 | - { | |
| 51 | - value: 'zhuozhengyuan', | |
| 52 | - label: '拙政园' | |
| 53 | - }, | |
| 54 | - { | |
| 55 | - value: 'shizilin', | |
| 56 | - label: '狮子林' | |
| 57 | - } | |
| 58 | - ] | |
| 59 | - } | |
| 60 | - ] | |
| 61 | - }]; | |
| 62 | - setTimeout(() => { | |
| 63 | - this.value = ['beijing', 'tiantan']; | |
| 64 | - }, 1000); | |
| 65 | - }, 1000); | |
| 62 | + handleChange (value, selectedData) { | |
| 63 | + this.text = selectedData.map(o => o.label).join(', '); | |
| 66 | 64 | } |
| 67 | - }, | |
| 68 | - ready () { | |
| 69 | - this.updateData(); | |
| 70 | 65 | } |
| 71 | 66 | } |
| 72 | 67 | </script> | ... | ... |