最近修改项目时碰到了一个超级难搞的错,网上搜索了一天之后发现是自己的失误造成的,写下来帮大家避避雷

我要实现的功能是在接口成功调用之后,根据返回的值弹窗显示成功和失败:像这样
像这样

//要测试的接口
test(params).then(res => {
              const result = res.result[0]
              this.$success({
                title: '测试结果',
                content: h => <div><p>匹配结果:{result.match ? '成功' : '失败'} </p><p>测试分数:{result.score}</p></div>
              })
            })

问题:

在这里插入图片描述

原因:

因为返回结果res里没有result,只有match,res.result[0]是undefined

解决方案:

test(params).then(res => {
              const result = res //修改的地方
              this.$success({
                title: '测试结果',
                content: h => <div><p>匹配结果:{result.match ? '成功' : '失败'} </p><p>测试分数:{result.score}</p></div>
              })
            })
Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐