「Vue3」template要素でv-ifを使うサンプル

書式
<template v-if="条件式">
要素
</template>
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue template test sample</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="vp">
<template v-if="seen">
<h1><font color="SkyBlue">A001</font></h1>
<p>B002</p>
<p>C003</p>
<p><font color="red">D004</font></p>
</template>
</div>
<script>
const vg = {
data() {
return {
seen: true /* true メッセージ表示 */
}
}
}
Vue.createApp(vg).mount('#vp')
</script>
</body>
</html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Vue template test sample</title> <script src="https://unpkg.com/vue@next"></script> </head> <body> <div id="vp"> <template v-if="seen"> <h1><font color="SkyBlue">A001</font></h1> <p>B002</p> <p>C003</p> <p><font color="red">D004</font></p> </template> </div> <script> const vg = { data() { return { seen: true /* true メッセージ表示 */ } } } Vue.createApp(vg).mount('#vp') </script> </body> </html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue template test sample</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="vp">
    <template v-if="seen">
            <h1><font color="SkyBlue">A001</font></h1>
        <p>B002</p>
        <p>C003</p>
            <p><font color="red">D004</font></p>
    </template>
</div>
    
<script>
const vg = {
  data() {
    return {
      seen: true /* true メッセージ表示 */
    }
  }
}
 
Vue.createApp(vg).mount('#vp')
</script>
</body>
</html>

 

Vue.js

Posted by arkgame