1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

エラー: The template root requires exactly one element

Last updated at Posted at 2021-05-08

20210508-131637.png

複数の要素を入れる場合は

divタグなどで1つに括ってあげる。

<template>
  <p>いいね({{ number }})</p>
  <button @click="increment">+1</button>
</template>

<script>
export default {
   data() {
     return {
       number: 7
     };
   },
   methods: {
     increment(){
       this.number += 1;
     }
   }
};
</script>
Failed to compile.

./src/LikeNumber.vue
Module Error (from ./node_modules/eslint-loader/index.js):

/Users/maedatakuo/projects/udemy-vuejs/src/LikeNumber.vue
  3:3  error  The template root requires exactly one element  vue/valid-template-root

✖ 1 problem (1 error, 0 warnings)
<template>
<div>
  <p>いいね({{ number }})</p>
  <button @click="increment">+1</button>
</div>
</template>

<script>
export default {
   data() {
     return {
       number: 7
     };
   },
   methods: {
     increment(){
       this.number += 1;
     }
   }
};
</script>

20210508-131409.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?