Form 模块

多级联动

多级联动 - 图1

  1. <avue-form v-model="data" :option="option" @submit="submit"></avue-form>
  2. <script>
  3. const baseUrl = `https://cli2.avue.top/api/area`
  4. export default {
  5. data() {
  6. return {
  7. data: {},
  8. option: {
  9. props: {
  10. label: 'name',
  11. value: 'code'
  12. },
  13. column: [
  14. {
  15. label: '省份',
  16. prop: 'province',
  17. type: 'select',
  18. cascaderItem: ['city', 'area'],
  19. dicUrl: `${baseUrl}/getProvince`,
  20. rules: [
  21. {
  22. required: true,
  23. message: '请选择省份',
  24. trigger: 'blur'
  25. }
  26. ]
  27. },
  28. {
  29. label: '城市',
  30. prop: 'city',
  31. type: 'select',
  32. dicFlag: false,
  33. dicUrl: `${baseUrl}/getCity/{{key}}`,
  34. rules: [
  35. {
  36. required: true,
  37. message: '请选择城市',
  38. trigger: 'blur'
  39. }
  40. ]
  41. },
  42. {
  43. label: '地区',
  44. prop: 'area',
  45. dicFlag: false,
  46. type: 'select',
  47. dicUrl: `${baseUrl}/getArea/{{key}}`,
  48. rules: [
  49. {
  50. required: true,
  51. message: '请选择地区',
  52. trigger: 'blur'
  53. }
  54. ]
  55. }
  56. ]
  57. }
  58. }
  59. },
  60. mounted() {
  61. this.data.province = '110000'
  62. this.data.city = '110100'
  63. this.data.area = '110101'
  64. },
  65. methods: {
  66. submit() {
  67. this.$message.success('当前数据' + JSON.stringify(this.data))
  68. }
  69. }
  70. }
  71. </script>

表格联动

多级联动 - 图2

  1. <avue-crud :option="option1" :data="data1" @submit="submit"></avue-crud>
  2. <script>
  3. const baseUrl = `https://cli2.avue.top/api/area`
  4. export default {
  5. data() {
  6. return {
  7. data1: [
  8. {
  9. name:'张三',
  10. province: '110000',
  11. city: '110100',
  12. area: '110101'
  13. },
  14. {
  15. name:'李四',
  16. province: '140000',
  17. city: '140600',
  18. area: '140623'
  19. }
  20. ],
  21. option1: {
  22. props: {
  23. label: 'name',
  24. value: 'code'
  25. },
  26. align: 'center',
  27. menuAlign: 'center',
  28. column: [{
  29. label:'姓名',
  30. prop:'name'
  31. },{
  32. label: '省份',
  33. prop: 'province',
  34. type: 'select',
  35. cascaderItem: ['city', 'area'],
  36. dicUrl: `${baseUrl}/getProvince`,
  37. rules: [
  38. {
  39. required: true,
  40. message: '请选择省份',
  41. trigger: 'blur'
  42. }
  43. ]
  44. },
  45. {
  46. label: '城市',
  47. prop: 'city',
  48. type: 'select',
  49. dicFlag: false,
  50. hide: true,
  51. dicUrl: `${baseUrl}/getCity/{{key}}`,
  52. rules: [
  53. {
  54. required: true,
  55. message: '请选择城市',
  56. trigger: 'blur'
  57. }
  58. ]
  59. },
  60. {
  61. label: '地区',
  62. prop: 'area',
  63. dicFlag: false,
  64. hide: true,
  65. type: 'select',
  66. dicUrl: `${baseUrl}/getArea/{{key}}`,
  67. rules: [
  68. {
  69. required: true,
  70. message: '请选择地区',
  71. trigger: 'blur'
  72. }
  73. ]
  74. }
  75. ]
  76. }
  77. }
  78. },
  79. methods: {
  80. submit() {
  81. this.$message.success('当前数据' + JSON.stringify(this.data))
  82. }
  83. }
  84. }
  85. </script>