I get this annoying 'error' message in Vue.js app.

error: Mixed spaces and tabs (no-mixed-spaces-and-tabs) at src/components/Landing.vue:388:2:

I'm wondering how can I suppress it?

推荐答案

That's an ESLint error (no-mixed-spaces-and-tabs), intended to warn against using both space and tab for indenting code. Consistency of spaces/tabs is a code convention, which is important when sharing a codebase within a team (1) (2). If you're swinging it alone (and have no plans otherwise), feel free to disable/enable any rules you want.

Disable rule per project

You can configure ESLint to ignore that error in your entire project. The configuration is usually stored in .eslintrc.js in a Vue CLI generated project. Inside that file, edit the rules object to contain:

// .eslintrc.js
module.exports = {
  "rules": {
    "no-mixed-spaces-and-tabs": 0, // disable rule
  }
}

Disable rule per line

To ignore that error for a single line only, use an inline comment (eslint-disable-line no-mixed-spaces-and-tabs or eslint-disable-next-line no-mixed-spaces-and-tabs) on that line:

⋅⋅const x = 1
⇥⋅⋅const y = 2 // eslint-disable-line no-mixed-spaces-and-tabs

// eslint-disable-next-line no-mixed-spaces-and-tabs
⇥⋅⋅const z = 3

Disable rule per section

To ignore that error for multiple lines of code, surround the code with eslint-disable no-mixed-spaces-and-tabs and eslint-enable no-mixed-spaces-and-tabs multi-line comments:

⋅⋅const x = 1

/* eslint-disable no-mixed-spaces-and-tabs */
⇥⋅⋅const y = 2  // ?
⇥⋅⋅const z = 3  // ?
/* eslint-enable no-mixed-spaces-and-tabs */

⇥⋅⋅const q = 4  // ❌ error: mixed spaces and tabs!

Vue.js相关问答推荐

设置Vite Vue 3需要多个应用程序输出目录

vuejs3 youtube-plugin YT 未定义控制台错误

在 Ajax 函数中访问 Vue.js 组件属性

VueJS:在组件之间使用全局对象的最佳实践?

从组件的 内的组件调用方法

Vuetify Datatable - 在所有列上启用内容编辑

Vuetify - 如何保持第一个扩展面板默认打开,如果我打开另一个面板,其他面板应该关闭?

如何根据生产或开发模式读取不同的 .env 文件?

在 SPA VueJS 中全局声明 mapState 和 mapMutations

错误:您可能需要额外的加载器来处理这些加载器的结果.

vuex: unknown getter: user

Laravel Blade 模板将数据传递给 Vue JS 组件

如何使用 TypeScript 在 Vue.js 中指定非react性实例属性?

如何在 vue.config.js 中为生产设置 API 路径?

执行调度程序刷新期间未处理的错误,这可能是一个 Vue 内部错误

使用 Vue 在单个文件组件中调用渲染方法

构建 Vue.js 应用程序时 JavaScript 堆内存不足

Vuejs获取事件正在调用的元素?

如何使用 Vue Test utils 测试输入是否聚焦?

从子组件 Vue 更新父模型