# no-literals-in-template

Rule `vue/no-literals-in-template`. Disallow object, array, and function literals in template

- Source: vue
- Technologies: Vue
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2063 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `vue/no-literals-in-template` | no | no | package `eslint-plugin-vue` | [docs](https://eslint.vuejs.org/rules/no-literals-in-template.html) |

## Code examples

### Incorrect: the rule reports this

```vue
  <div :arr="[]" />
  <div :arr="[1, 2, 3]" />
  <div :obj="{}" />
  <div :obj="{ name: 'Tom', age: 123 }" />
  <div :callback="() => someFunction(someArgs)" />
  <div :callback="function() { return 1 }" />

  <template v-for="i in arr">
    <MyComponent :data="[globalVars]" />
    <MyComponent :data="{ index: globalVars }" />
    <MyComponent :callback="() => someFunction(someArgs, globalVars)" />
  </template>

  <Child>
    <template #default="{ foo }">
      <MyComponent :data="[globalVars]" />
      <MyComponent :data="{ val: globalVars }" />
      <MyComponent :data="() => someFunction(someArgs, globalVars)" />
    </template>
  </Child>
</template>
```

```vue
  <MyComponent :wrapper-class="[{ active: isActive }]" />
</template>
```

### Correct: the rule accepts this

```vue
<div :arr="myArray" />
<div :obj="myObject" />
<div :callback="myFunction" />
<div arr="[]" />
<!-- class and style bindings are ignored -->
<div :class="{ active: isActive }" />
<div :style="{ color: 'red' }" />

<template v-for="i in arr">
  <MyComponent :data="[i]" />
  <MyComponent :data="{ index: i }" />
  <MyComponent :callback="() => someFunction(someArgs, i)" />
</template>

<Child>
  <template #default="{ foo }">
    <MyComponent :data="[foo]" />
    <MyComponent :data="{ val: foo }" />
    <MyComponent :data="() => someFunction(someArgs, foo)" />
  </template>
</Child>
```

```vue
<MyComponent
  :slot-class="[{ active: isActive }]"
  :slot-style="{ color: themeColor }"
/>
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import vue from "eslint-plugin-vue";

export default [
  {
    plugins: { vue },
    rules: {
      "vue/no-literals-in-template": "error",
    },
  },
];
```

## Related rules

- [vue/no-extra-parens](https://lintradar.dev/rules/vue/no-extra-parens.md): Disallow unnecessary parentheses in `<template>`
- [vue/no-potential-component-option-typo](https://lintradar.dev/rules/vue/no-potential-component-option-typo.md): Disallow a potential typo in your component property
- [vue/no-empty-component-block](https://lintradar.dev/rules/vue/no-empty-component-block.md): Disallow the `<template>` `<script>` `<style>` block to be empty
- [vue/no-props-shadow](https://lintradar.dev/rules/vue/no-props-shadow.md): Disallow declarations that shadow props in `<script setup>`
- [vue/no-duplicate-class-names](https://lintradar.dev/rules/vue/no-duplicate-class-names.md): Disallow duplication of class names in class attributes
- [vue/no-restricted-block](https://lintradar.dev/rules/vue/no-restricted-block.md): Disallow specific block

---

Web page: https://lintradar.dev/rules/vue/no-literals-in-template. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
