Closed1

【Vue.js】template

seiya2130seiya2130
  • DOMに出力されない仮想なラッパー要素
  • 出力されないためコード上の構造化のために利用でき、余計なDOMを出力しなくて済む
  • v-ifやv-forなどで要素のグルーピングによく使われる
<template>
  <template v-if="flg">
    <h1>Title</h1>
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
  </template>

  <ul>
    <template v-for="item in [1, 2, 3]">
      <li>{{ item }}</li>
    </template>
  </ul>
</template>
<script setup lang="ts">
import { ref } from 'vue';

const flg = ref(false);

</script>

template要素はレンダリングされない

参考

https://ja.vuejs.org/api/built-in-special-elements#template

このスクラップは6ヶ月前にクローズされました