vue/prefer-use-template-ref
eslint-plugin-vue
No autofix
eslint.config.js
import vue from "eslint-plugin-vue";
export default [
{
plugins: { vue },
rules: {
"vue/prefer-use-template-ref": "error",
},
},
];Require using useTemplateRef instead of ref/shallowRef for template refs
<template>
<input ref="input" />
</template>
<script setup>
import { ref } from "vue";
const input = ref();
</script><template>
<div ref="root" />
</template>
<script setup>
import { shallowRef } from "vue";
const root = shallowRef(null);
</script><template>
<input ref="input" />
<button :ref="(el) => (button = el)">Send</button>
</template>
<script setup>
import { ref, useTemplateRef } from "vue";
const inputElement = useTemplateRef("input");
const button = ref();
</script>Examples from the Biome documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
vue/prefer-use-template-ref
eslint-plugin-vue
import vue from "eslint-plugin-vue";
export default [
{
plugins: { vue },
rules: {
"vue/prefer-use-template-ref": "error",
},
},
];Oxlint does not have this rule.
nursery/useVueTemplateRef
nursery · since 2.6.4
{
"linter": {
"rules": {
"nursery": {
"useVueTemplateRef": "error"
}
}
}
}Require shorthand form attribute when v-bind value is true
Enforce passing a single argument to custom event emissions
Enforce Boolean comes first in component prop types