vue/no-mutating-props
Disallow mutating component props.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
essential, happy-path, nuxt, ecosystem, opinionated |
No | Rule options |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
A type assertion does not change the value it wraps, so (rows as string[]).push(x) and rows!.push(x) in a template are reported as mutations of the prop rows; eslint-plugin-vue stops at the assertion.
Bad
Incrementing props.count writes directly to a value supplied by the parent.
<script setup lang="ts">
const props = defineProps<{ count: number }>();
props.count++;
</script>
Good
The component emits update:count with the next value, leaving the parent responsible for updating the prop.
<script setup lang="ts">
const props = defineProps<{ count: number }>();
const emit = defineEmits<{ "update:count": [value: number] }>();
function increment() {
emit("update:count", props.count + 1);
}
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/no-mutating-props": "error"
}
},
});
Then run vp run lint.