mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-02 11:17:46 +08:00
5844947198
* refactor(components): [select&select-v2] refactor components * refactor(components): [select-v2] * refactor(components): update * refactor(components): update * refactor(components): [select-v2] update * refactor(components): update * refactor(components): update * refactor(components): update type * refactor(components): update * refactor(components): update * refactor(components): update style * refactor(components): update docs * refactor(components): update * refactor(components): fix #15323 * refactor(theme-chalk): update * refactor(components): update * refactor(components): update * refactor(components): update * refactor(components): fix bugs * fix(components): fix issue * fix(components): update * fix(components): fix some bug * feat(components): update * feat(components): add tag slot * feat(components): update * fix(components): update * style(theme-chalk): update style * fix(theme-chalk): update * feat(theme-chalk): update * fix(components): update * feat: update * feat: update * feat: update * feat(components): update
90 lines
1.7 KiB
Vue
90 lines
1.7 KiB
Vue
<template>
|
|
<el-select v-model="value" placeholder="Select" style="width: 240px">
|
|
<el-option
|
|
v-for="item in cities"
|
|
:key="item.value"
|
|
:label="item.label"
|
|
:value="item.value"
|
|
/>
|
|
<template #footer>
|
|
<el-button v-if="!isAdding" text bg size="small" @click="onAddOption">
|
|
Add an option
|
|
</el-button>
|
|
<template v-else>
|
|
<el-input
|
|
v-model="optionName"
|
|
class="option-input"
|
|
placeholder="input option name"
|
|
size="small"
|
|
/>
|
|
<el-button type="primary" size="small" @click="onConfirm">
|
|
confirm
|
|
</el-button>
|
|
<el-button size="small" @click="clear">cancel</el-button>
|
|
</template>
|
|
</template>
|
|
</el-select>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue'
|
|
|
|
import type { CheckboxValueType } from 'element-plus'
|
|
|
|
const isAdding = ref(false)
|
|
const value = ref<CheckboxValueType[]>([])
|
|
const optionName = ref('')
|
|
const cities = ref([
|
|
{
|
|
value: 'Beijing',
|
|
label: 'Beijing',
|
|
},
|
|
{
|
|
value: 'Shanghai',
|
|
label: 'Shanghai',
|
|
},
|
|
{
|
|
value: 'Nanjing',
|
|
label: 'Nanjing',
|
|
},
|
|
{
|
|
value: 'Chengdu',
|
|
label: 'Chengdu',
|
|
},
|
|
{
|
|
value: 'Shenzhen',
|
|
label: 'Shenzhen',
|
|
},
|
|
{
|
|
value: 'Guangzhou',
|
|
label: 'Guangzhou',
|
|
},
|
|
])
|
|
|
|
const onAddOption = () => {
|
|
isAdding.value = true
|
|
}
|
|
|
|
const onConfirm = () => {
|
|
if (optionName.value) {
|
|
cities.value.push({
|
|
label: optionName.value,
|
|
value: optionName.value,
|
|
})
|
|
clear()
|
|
}
|
|
}
|
|
|
|
const clear = () => {
|
|
optionName.value = ''
|
|
isAdding.value = false
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.option-input {
|
|
width: 100%;
|
|
margin-bottom: 8px;
|
|
}
|
|
</style>
|