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 的最佳实践,将逻辑从模板中移到组件方法中

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


相关推荐
木头没有瓜几秒前
vscode离线安装插件
ide·vue.js·vscode
伍哥的传说44 分钟前
鸿蒙系统(HarmonyOS)应用开发之手势锁屏密码锁(PatternLock)
前端·华为·前端框架·harmonyos·鸿蒙
yugi9878381 小时前
前端跨域问题解决Access to XMLHttpRequest at xxx from has been blocked by CORS policy
前端
浪裡遊1 小时前
Sass详解:功能特性、常用方法与最佳实践
开发语言·前端·javascript·css·vue.js·rust·sass
旧曲重听12 小时前
最快实现的前端灰度方案
前端·程序人生·状态模式
默默coding的程序猿2 小时前
3.前端和后端参数不一致,后端接不到数据的解决方案
java·前端·spring·ssm·springboot·idea·springcloud
夏梦春蝉2 小时前
ES6从入门到精通:常用知识点
前端·javascript·es6
归于尽2 小时前
useEffect玩转React Hooks生命周期
前端·react.js
G等你下课2 小时前
React useEffect 详解与运用
前端·react.js
我想说一句2 小时前
当饼干遇上代码:一场HTTP与Cookie的奇幻漂流 🍪🌊
前端·javascript