ant-design-vue/components/cascader/demo/custom-render.md

86 lines
2.0 KiB
Markdown
Raw Normal View History

2018-03-04 08:02:46 +00:00
<cn>
#### 自定义已选项
例如给最后一项加上邮编链接。
</cn>
<us>
#### Custom render
For instance, add an external link after the selected value.
</us>
```html
<template>
2019-09-28 12:45:07 +00:00
<a-cascader
:options="options"
:defaultValue="['zhejiang', 'hangzhou', 'xihu']"
style="width: 100%"
>
2018-03-10 05:34:26 +00:00
<template slot="displayRender" slot-scope="{labels, selectedOptions}">
<span v-for="(label, index) in labels" :key="selectedOptions[index].value">
<span v-if="index === labels.length - 1">
2019-09-28 12:45:07 +00:00
{{label}} (<a @click="e => handleAreaClick(e, label, selectedOptions[index])"
>{{selectedOptions[index].code}}</a
>)
2018-03-04 08:02:46 +00:00
</span>
<span v-else @click="onChange">
2019-09-28 12:45:07 +00:00
{{label}} /
2018-03-04 08:02:46 +00:00
</span>
</span>
</template>
</a-cascader>
</template>
<script>
2019-09-28 12:45:07 +00:00
export default {
data() {
return {
options: [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [
{
value: 'hangzhou',
label: 'Hangzhou',
children: [
{
value: 'xihu',
label: 'West Lake',
code: 752100,
},
],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
code: 453400,
},
],
},
],
},
],
};
2018-03-04 08:02:46 +00:00
},
2019-09-28 12:45:07 +00:00
methods: {
onChange(value) {
console.log(value);
},
handleAreaClick(e, label, option) {
e.stopPropagation();
console.log('clicked', label, option);
},
2018-03-04 08:02:46 +00:00
},
2019-09-28 12:45:07 +00:00
};
2018-03-04 08:02:46 +00:00
</script>
```