<template>
<a-select
class="J-select"
:mode="mode"
:show-search="showSearch"
:value="value"
:placeholder="placeholder"
:style="selectStyle"
:default-active-first-option="defaultActiveFirstOption"
:show-arrow="showArrow"
:filter-option="filterOption"
:not-found-content="notFoundContent"
@search="handleSearch"
@change="handleChange"
>
<slot></slot>
<a-select-option v-for="d in options" :value="d.value" :key="d.value">
{{ d.text }}
</a-select-option>
</a-select>
</template>
<script>
import { getAction } from '../../api/manage'
export default {
name: 'JSelect',
props: {
mode: {
type: String,
default: 'default'
},
url: {
type: String,
default: ''
},
paramsData: {
type: Object,
default: () => {
return {}
}
},
textName: {
type: String
},
valueName: {
type: String
},
value: {
type: String,
default: undefined //此处如果不是undefined 那么placeholder不会显示 会有一个默认为空的占位符 无法删除
},
showSearch: {
type: Boolean,
default: false
},
defaultActiveFirstOption: {
type: Boolean,
default: false
},
showArrow: {
type: Boolean,
default: false
},
filterOption: {
type: Boolean,
default: false
},
notFoundContent: {
type: String,
default: '未找到'
},
placeholder: {
type: String,
default: '请输入',
required: false
},
searchName:{
type: String,
default: 'type'
},
selectStyle: {
type: Object,
default: () => {
return {
width: ''
}
}
},
triggerChange: {
type: Boolean,
required: false,
default: false
}
},
data() {
return {
options: [],
paramsSearch: {}
}
},
mounted() {
this.fetch()
},
methods: {
fetch() {
getAction(this.url, { ...this.paramsSearch, ...this.paramsData }).then(res => {
if (res.success) {
console.log(res.result)
let data = [...res.result]
let newData = []
data.map(i => {
newData.push({ text: i[this.textName], value: i[this.valueName] })
})
this.options = [...newData]
}
})
},
handleSearch(value) {
console.log(value)
this.paramsSearch = {
[this.searchName]: value
}
this.fetch()
},
handleChange(value) {
console.log(value)
if (this.triggerChange) {
this.$emit('change', value)
} else {
this.$emit('input', value)
}
}
}
}
</script>
<style scoped>
.J-select {
width: 100%;
}
</style>
select 组件 如果启用 可搜索模式 默认值必须是 undefined
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 原文路径:https://blog.csdn.net/qq_36356218/article/details/10...
- 1、angularjs中下拉框select option默认值 (1)第一种方式 (2)第二种方式 2、sprin...
- 欢迎留言交流小程序问题 欢迎留言交流小程序问题 欢迎留言交流小程序问题 我们新建一个组件test作为测试,test...