唯爱赞多 2021-07-25 15:47 采纳率: 50%
浏览 66
已结题

用路径'${this.id}'报错,直接后面+this.id就成功 求解${this.id}

在vue+mongoose+nodejs(express)项目

img
用这种没问题

img
用这种就报错
CastError: Cast to ObjectId failed for value "${this.id}" (type string) at path "_id" for model "Category"
messageFormat: undefined,
stringValue: '"${this.id}"',
kind: 'ObjectId',
value: '${this.id}',
path: '_id',
reason: Error: Argument passed in must be
a single String of 12 bytes or a string of 24 hex characters

他们说是模版字符串的问题,然后我去看了不知道怎么写,求解

  • 写回答

2条回答 默认 最新

  • 崽崽的谷雨 2021-07-26 12:34
    关注

    模板字符串需要``符号包裹

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月4日
  • 已采纳回答 7月27日
  • 修改了问题 7月25日
  • 创建了问题 7月25日