JSONSchema

基本用法

1.10.0 及以上版本

此组件还在实验阶段,很多 json-schema 属性没有对应实现,使用前请先确认你要的功能满足了需求

基于 json-schema 定义生成表单输入项。

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, debug: true, “body”: [ { “type”: “json-schema”, “name”: “value”, “label”: “字段值”, “schema”: { type: ‘object’, properties: { id: { type: ‘number’, title: ‘ID’ }, name: { type: ‘string’, title: ‘名称’ }, description: { type: ‘string’, title: ‘描述’ } } } } ] }

  1. ## 复杂 case
  2. ```schema: scope="body"
  3. {
  4. "type": "form",
  5. "api": "/api/mock2/form/saveForm",
  6. debug: true,
  7. "body": [
  8. {
  9. "type": "json-schema",
  10. "name": "value",
  11. "label": "字段值",
  12. "schema": {
  13. type: 'object',
  14. additionalProperties: false,
  15. required: ['id', 'name'],
  16. properties: {
  17. id: {
  18. type: 'number',
  19. title: 'ID'
  20. },
  21. name: {
  22. type: 'string',
  23. title: '名称'
  24. },
  25. description: {
  26. type: 'string',
  27. title: '描述'
  28. },
  29. date: {
  30. type: 'object',
  31. title: '日期',
  32. additionalProperties: false,
  33. required: ['year', 'month', 'day'],
  34. properties: {
  35. year: {
  36. type: 'number',
  37. title: '年'
  38. },
  39. month: {
  40. type: 'number',
  41. title: '月'
  42. },
  43. day: {
  44. type: 'number',
  45. title: '日'
  46. }
  47. }
  48. },
  49. tag: {
  50. type: 'array',
  51. title: '个人标签',
  52. items: {
  53. type: 'string'
  54. },
  55. minContains: 2,
  56. maxContains: 10
  57. }
  58. }
  59. }
  60. }
  61. ]
  62. }

远程获取 schema

schema: scope="body" { "type": "form", debug: true, "body": [ { "type": "json-schema", "name": "value", "label": "字段值", "schema": "/api/mock2/json-schema" } ] }

属性表

属性名 类型 默认值 说明
schema object \ string 指定 json-schema