amis icon indicating copy to clipboard operation
amis copied to clipboard

requestAdaptor 使用 mockResponse 报错

Open WowChenEd opened this issue 1 year ago • 3 comments

描述问题:

请用一段清晰简洁的文字描述问题是什么...

根据文档https://aisuda.bce.baidu.com/amis/zh-CN/docs/types/api#%E6%8B%A6%E6%88%AA%E8%AF%B7%E6%B1%82 配置mockResponse 报错Cannot set properties of undefined (setting 'Content-Type') sdk.js:1909 TypeError: Cannot set properties of undefined (setting 'Content-Type') at Object. (sdk.js:3611:2939) at sdk.js:11:4440 at Object.next (sdk.js:11:4545) at a (sdk.js:11:3262)

截图或视频:

image

可以的话,尽可能提供截图或视频来补充描述你的问题...

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的? sdknpm其他... sdk

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在 6.1.0

  3. 粘贴有问题的完整 amis schema 代码:

code here...
requestAdaptor(api) {
        // 支持异步,可以通过 api.mockResponse 来设置返回结果,跳过真正的请求发送
        // 此功能自定义 fetcher 的话会失效
        // api.context 中包含发送请求前的上下文信息
        console.log(api, api.context, api.mockResponse)
        if (api.url === '/admin/signout') {
          return {
            // 模拟 http 请求返回
            mockResponse: {
              status: 200, // http 返回状态
              data: {
                // http 返回结果
                status: 0, // amis 返回数据的状态
                data: {
                  name: '模拟返回的值'
                }
              }
            }
          }
        }
        return api
      },
  1. 操作步骤 请简单描述一下复现的操作步骤...

WowChenEd avatar Feb 01 '24 02:02 WowChenEd

👍 Thanks for this! 🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

github-actions[bot] avatar Feb 01 '24 02:02 github-actions[bot]

mockReponse 里面补上 header 应该能临时解决

mockResponse: {
              status: 200, // http 返回状态
              headers: {},
              data: {
                // http 返回结果
                status: 0, // amis 返回数据的状态
                data: {
                  name: '模拟返回的值'
                }
              }
            }

2betop avatar Feb 02 '24 08:02 2betop

mockReponse 里面补上 header 应该能临时解决

mockResponse: {
              status: 200, // http 返回状态
              headers: {},
              data: {
                // http 返回结果
                status: 0, // amis 返回数据的状态
                data: {
                  name: '模拟返回的值'
                }
              }
            }

实测还是一样的问题

WowChenEd avatar Feb 04 '24 06:02 WowChenEd