vue/prefer-const
Require const for bindings the script and template never reassign.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
nuxt, opinionated |
No | None |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The template reads label, and neither the script nor the template reassigns it, so let is wider than the binding needs.
<script setup>
let label = "Hello";
</script>
<template><p>{{ label }}</p></template>
Good
const matches a binding that the script and the template only read.
<script setup>
const label = "Hello";
</script>
<template><p>{{ label }}</p></template>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/prefer-const": "warn"
}
},
});
Then run vp run lint.