Vue2 使用插件 Volar 报错:<template v-for> key should be placed on the <template> tag.

原因

具体原因可以参考:https://www.cnblogs.com/jarvismusk/p/15504455.html

总结

大体意思就是 eslint-plugin-vue 规则在关于key是否能置于<template v-for>上的冲突了。

解决办法:

参考上面的博文操作以后没有成功,使用的办法是将 template 替换成 div ,具体操作如下:

原报错代码:
在这里插入图片描述

修改后:
在这里插入图片描述

简单点说就是:
1.首先将原来的 template 替换成 div
2.然后在 div 的后面添加 key 的值。

这样就避开了eslint检测了,优点是简单实用,缺点就是会多一层div。

猜你喜欢

转载自blog.csdn.net/weixin_35773751/article/details/124658430