当前位置:   article > 正文

Ant Design Vue组件中的Select 选择器实现全选/全不选功能_a-select 全选

a-select 全选

效果

代码

  1. <template>
  2. <a-select
  3. :value="text"
  4. placeholder="请选择类型"
  5. style="width:100%"
  6. showArrows
  7. mode="multiple"
  8. @change="onchange"
  9. >
  10. <div slot="dropdownRender" slot-scope="menu">//全选插槽
  11. <v-nodes :vnodes="menu" />
  12. <a-divider style="margin: 4px 0;" />
  13. <div style="padding: 4px 8px; cursor: pointer;" @mousedown="e => e.preventDefault()">
  14. <a-button type="link" @click="selectAll">全选</a-button>
  15. <a-button type="link" @click="clearAll">清空</a-button>
  16. </div>
  17. </div>
  18. <a-select-option v-for="(item,index) in couponTypeOpts" :key="index" >
  19. {{ item.label }}
  20. </a-select-option>
  21. </a-select>
  22. </template>
  23. <script>
  24. export default {
  25. name:"all-select",
  26. props: {
  27. dict:String
  28. },
  29. components:{
  30. VNodes: {
  31. functional: true,
  32. render: (h, ctx) => ctx.props.vnodes
  33. }
  34. },
  35. data() {
  36. return {
  37. text:[],
  38. couponTypeOpts:[],
  39. }
  40. },
  41. watch: {
  42. text(val) {
  43. this.$emit('input', val);
  44. },
  45. },
  46. created() {
  47. console.log(this.dict)
  48. this.getCouponType()
  49. },
  50. methods: {
  51. getCouponType(){
  52. this.$getDict(this.dict).then((list)=>{
  53. list = list.map((i)=>{
  54. return {
  55. label: i.dictLabel,
  56. value: i.dictValue
  57. }
  58. })
  59. this.couponTypeOpts = list;
  60. })
  61. },
  62. onchange(value){
  63. console.log(value)
  64. this.text=value
  65. },
  66. selectAll(){
  67. this.text=[]
  68. this.text=this.couponTypeOpts.map((item,index)=>{
  69. return Number(index)
  70. })
  71. console.log(this.text)
  72. },
  73. clearAll(){
  74. this.text=[]
  75. }
  76. },
  77. }
  78. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/151727
推荐阅读
相关标签
  

闽ICP备14008679号