网站搜索

vue.js - 在模板块中忽略 VueJs Typescript 的 TypeScript 错误


在我的 VueJs 应用中,一切都按预期工作。唯一让我烦恼的是模板块中的 TypeScript 错误。有没有类似于我在脚本块中会使用的选项?

<script setup lang="ts">
//@ignore-ts
this line will be ignored of typescript errors
</script>

<template>
<!-- @ignore-ts -->
this does not work and this line still has a typescript error
</template>

答案#1

你可以使用 <!-- @vue-ignore --> #3215。例如:

<template>
  <!-- @vue-ignore -->
  <HelloWorld :msg="wrongType" />

  <!-- @vue-expect-error Describe your error here -->
  <HelloWorld :msg="wrongType" />

  <!-- @vue-skip -->
  <SomethingYouDontWantVolarToRecognizeIt>
    ...
  </SomethingYouDontWantVolarToRecognizeIt>
</template>

答案#2

我终于找到了我的解决方案。//@ts-ignore 仍然是我问题的解决办法,但最重要的是,之后按一下 Enter 就会产生神奇的效果。

如果在模板块中的 v-if=""、v-model=""、v-for="" 等指令中遇到 TypeScript 错误让你烦恼,你可以这样忽略它:

Typescript 错误抛出代码行:

<div v-if="value.input_type === 'text'">

忽略 TypeScript 错误的代码行:

<div v-if="//@ts-ignore 
    value.input_type === 'text'">

如果 TypeScript 错误在模板块中的 mustache(即双大括号)中惹恼了你,请这样做:

Typescript 错误抛出代码行:

<h3>{{value.label }}</h3>

忽略 TypeScript 错误的代码行:

<h3>{{//@ts-ignore
       value.label }}</h3>

相关文章