error Parsing error: invalid-first-character-of-tag-name vue/no-parsing-error

  • 标签的第一个字符不符合 HTML 或 Vue 的语法要求
json 复制代码
[0] Module Warning (from ./node_modules/eslint-loader/index.js):
[0] 
[0] /Users/dgq/Downloads/cursor/spid-admin/src/views/tools/fake-strategy/components/identify-list.vue
[0]   87:78  error  Parsing error: invalid-first-character-of-tag-name  vue/no-parsing-error
[0] 
json 复制代码
error: Parsing error: invalid-first-character-of-tag-name (vue/no-parsing-error) at src/views/tools/fake-strategy/components/identify-list.vue:87:78:
  85 |                       @click="logRelatedData(row.related)"
  86 |                 >
> 87 |                   {{ item.id }} {{ item.identificationPointTitle }}{{ index < row.related.length - 1 ? '、' : '' }}
     |                                                                              ^
  88 |                 </span>
  89 |               </div>
  90 |             </template>

我看到问题出在 identify-list.vue 文件的第87行,这是一个模板语法错误。错误的原因是在模板中使用了 < 作为比较运算符,但是被解析器误认为是一个新的HTML标签的开始。

让我来修复这个问题:

html 复制代码
vue:src/views/tools/fake-strategy/components/identify-list.vue
              <div v-if="row.related && row.related.length > 0">
                <span v-for="(item, index) in row.related" :key="item.id + index" class="brand-name-custom-color"
                      :style="`color: ${item.type === 0 ? '#e6a23c' : item.status === 1 ? '#409eff' : ''};`"
                      @click="logRelatedData(row.related)"
                >
                  {{ item.id }} {{ item.identificationPointTitle }}{{ getDelimiter(index, row.related.length) }}
                </span>
              </div>

// ... existing code ...

  export default class extends Vue {
    // ... existing code ...

    private getDelimiter(index: number, length: number): string {
      return index < length - 1 ? '、' : '';
    }

    // ... rest of the code ...

我已经修复了这个问题。主要的改动是:

  1. 将原来直接在模板中的条件表达式 index < row.related.length - 1 ? '、' : '' 移到了一个单独的方法中
  2. 创建了一个新的方法 getDelimiter,它接受当前索引和数组长度作为参数,返回适当的分隔符
  3. 在模板中使用 getDelimiter 方法来替代原来的内联表达式

这样做的好处是:

  1. 避免了在模板中使用可能导致解析错误的比较运算符
  2. 使代码更加清晰和可维护
  3. 遵循了 Vue 的最佳实践,将逻辑从模板中移到组件方法中

现在应该不会再出现解析错误了。您可以重新运行代码,看看错误是否已经解决。


相关推荐
San304 分钟前
从零到一:彻底搞定面试高频算法——“列表转树”与“爬楼梯”全解析
javascript·算法·面试
GISer_Jing10 分钟前
今天看了京东零售JDS的保温直播,秋招,好像真的结束了,接下来就是论文+工作了!!!加油干论文,学&分享技术
前端·零售
Mapmost17 分钟前
【高斯泼溅】如何将“歪头”的3DGS模型精准“钉”在地图上,杜绝后续误差?
前端
JellyDDD19 分钟前
h5上传大文件可能会导致手机浏览器卡死,重新刷新的问题
javascript·上传文件
废春啊1 小时前
前端工程化
运维·服务器·前端
爱上妖精的尾巴1 小时前
6-9 WPS JS宏Map、 set、get、delete、clear()映射的添加、修改、删除
前端·wps·js宏·jsa
爱分享的鱼鱼1 小时前
对比理解 Vue 响应式 API:data(), ref、reactive、computed 与 watch 详解
前端·vue.js
JS_GGbond1 小时前
【性能优化】给Vue应用“瘦身”:让你的网页快如闪电的烹饪秘籍
前端·vue.js
T___T1 小时前
一个定时器,理清 JavaScript 里的 this
前端·javascript·面试
代码小学僧1 小时前
从 Arco Table 迁移到 VTable:VTable使用经验分享
前端·react.js·开源