Skip to content

noVueDefineModelDefault (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueDefineModelDefault": "error"
}
}
}
}

Disallow default values in Vue’s defineModel().

defineModel() declares a value that a parent component binds with v-model. When the parent passes undefined, for example because its variable has no initial value yet, the child component uses the default value instead. The parent still holds undefined, so the two components show different values for the same model until one of them updates it.

To avoid this, don’t give the model a default value. Give the variable an initial value in the parent component instead.

<script setup>
const model = defineModel({ type: String, default: "" });
</script>
code-block.vue:2:52 lint/nursery/noVueDefineModelDefault ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The model modelValue has a default value.

1 │ <script setup>
> 2 │ const model = defineModel({ type: String, default: "" });
│ ^^
3 │ </script>
4 │

ℹ When the parent component passes undefined with v-model, this component uses the default value while the parent keeps undefined. The two components then show different values.

ℹ Remove the default value, and give the variable an initial value in the parent component instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script setup lang="ts">
const count = defineModel<number>("count", { default: 0 });
</script>
code-block.vue:2:55 lint/nursery/noVueDefineModelDefault ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The model count has a default value.

1 │ <script setup lang="ts">
> 2 │ const count = defineModel<number>("count", { default: 0 });
│ ^
3 │ </script>
4 │

ℹ When the parent component passes undefined with v-model, this component uses the default value while the parent keeps undefined. The two components then show different values.

ℹ Remove the default value, and give the variable an initial value in the parent component instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script setup lang="ts">
const model = defineModel({ type: String, required: true });
const count = defineModel<number>("count");
</script>