vue.js - VueJs Typescript 忽略 template 區塊中的 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'">
如果在 mustache 中,也就是模板區塊中的雙大括號出現 TypeScript 錯誤讓你感到困擾,請這樣做:
Typescript 錯誤拋出程式碼行:
<h3>{{value.label }}</h3>
忽略 Typescript 錯誤的程式碼行:
<h3>{{//@ts-ignore
value.label }}</h3>
