Vue: Invalid prop index只接受字符串报错解
2020-03-11 本文已影响0人
浪男博人
在写Vue的时候,标签index属性必须接受字符串String类型的数据,否则会报错。
但是如果引入的数据是数字形式,则会报错:
[Vue warn]: Invalid prop: type check failed for prop "index". Expected String with value "125", got Number with value 125.

如何解决呢?
需要在标签属性的引入值后面拼接一个空的string,

原来是 index="item.id"
修改后变成 index="item.id + ' ' "
因为String和任何属性的拼接都会变成String。