Picker组件

介绍

提供多个选项集合供用户选择其中一项。

安装

  1. import { createApp } from 'vue';
  2. import { Picker } from '@nutui/nutui';
  3. const app = createApp();
  4. app.use(Picker);

代码演示

基础用法

  1. <nut-cell title="请选择城市" :desc="desc" @click="open"></nut-cell>
  2. <nut-picker
  3. v-model:visible="show"
  4. :list-data="listData"
  5. title="城市选择"
  6. @confirm="confirm"
  7. ></nut-picker>
  1. <script>
  2. export default createDemo({
  3. setup(props, { emit }) {
  4. const show = ref(false);
  5. const listData = [
  6. '南京市',
  7. '无锡市',
  8. '海北藏族自治区',
  9. '北京市',
  10. '连云港市',
  11. '浙江市',
  12. '江苏市'
  13. ];
  14. return {
  15. listData,
  16. open: (index) => {
  17. show.value = true;
  18. },
  19. confirm: (res) => {
  20. desc.value = res;
  21. }
  22. };
  23. }
  24. });
  25. </script>

多列样式

  1. <nut-cell title="请选择时间" :desc="desc" @click="open"></nut-cell>
  2. <nut-picker
  3. v-model:visible="show"
  4. :list-data="listData"
  5. title="多列选择"
  6. @confirm="confirm"
  7. @close="close"
  8. ></nut-picker>
  1. <script>
  2. export default createDemo({
  3. setup(props, { emit }) {
  4. const show = ref(false);
  5. const listData = [
  6. {
  7. values: ['周一', '周二', '周三', '周四', '周五'],
  8. defaultIndex: 2
  9. },
  10. // 第二列
  11. {
  12. values: ['上午', '下午', '晚上'],
  13. defaultIndex: 1
  14. }
  15. ];
  16. return {
  17. listData,
  18. open: (index) => {
  19. show.value = true;
  20. },
  21. confirm: (res) => {
  22. desc.value = res.join(' ');
  23. }
  24. };
  25. }
  26. });
  27. </script>

多级联动

  1. <nut-cell title="地址" :desc="desc" @click="open"></nut-cell>
  2. <nut-picker
  3. v-model:visible="show"
  4. :list-data="listData"
  5. title="地址选择"
  6. @confirm="confirm"
  7. ></nut-picker>
  1. <script>
  2. export default createDemo({
  3. setup(props, { emit }) {
  4. const show = ref(false);
  5. const listData = [
  6. {
  7. text: '浙江',
  8. children: [
  9. {
  10. text: '杭州',
  11. children: [{ text: '西湖区' }, { text: '余杭区' }]
  12. },
  13. {
  14. text: '温州',
  15. children: [{ text: '鹿城区' }, { text: '瓯海区' }]
  16. }
  17. ]
  18. },
  19. {
  20. text: '福建',
  21. children: [
  22. {
  23. text: '福州',
  24. children: [{ text: '鼓楼区' }, { text: '台江区' }]
  25. },
  26. {
  27. text: '厦门',
  28. children: [{ text: '思明区' }, { text: '海沧区' }]
  29. }
  30. ]
  31. }
  32. ];
  33. return {
  34. listData,
  35. open: (index) => {
  36. show.value = true;
  37. },
  38. confirm: (res) => {
  39. desc.value = res.join(' ');
  40. }
  41. };
  42. }
  43. });
  44. </script>

API

Props

参数说明类型默认值
v-model:visible是否可见Booleanfalse
title设置标题String-
list-data列表数据Array-
default-value-index初始选中项的索引,默认为 0number0

Events

事件名说明回调参数
close关闭弹窗时触发event: Event
confirm点击确认时候触发event: Event
change改变时触发val

Picker  选择器 - 图1