Template should not be defined redundantly for a Vue component
- VUE_REDUNDANT_TEMPLATE
- Error
- Medium
- vue
This rule applies when template or render
function is defined multiple times in different ways for a Vue component.
It can be applied to the following cases:
- Both
render
andtemplate
properties are declared in the same Vue option object. In this case, therender
property has higher priority thantemplate
, sotemplate
property will be ignored. - Both
<template>
element andrender
property are declared in the same.vue
file. In this case, the<template>
element has higher priority thanrender
property, sorender
property will be ignored. - Both
<template>
element andtemplate
property are declared in the same.vue
file. In this case, the<template>
element has higher priority thantemplate
property, sotemplate
property will be ignored.
Noncompliant Code Example
View with compliant examples side by side<template>
<HelloWorld />
</template>
<script>
import HelloWorld from './components/HelloWorld';
export default {
name: 'App',
components: {
HelloWorld
},
template: '<HelloWorld />', // VUE_REDUNDANT_TEMPLATE alarm
render(createElement) { // VUE_REDUNDANT_TEMPLATE alarm
return createElement(HelloWorld);
}
}
</script>
Compliant Code Example
View with noncompliant examples side by side<template>
<HelloWorld />
</template>
<script>
import HelloWorld from './components/HelloWorld';
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>
Version
This rule was introduced in DeepScan 1.18.0.