条件渲染


指令释义
v-if 相当于: if
v-else 相当于:else
v-else-if 相当于:else if
DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>if、else if、elsetitle>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js">script>
head>
<body>
<div id="box">
    <h3>案例:if、else if、elseh3>
    <h2 v-if="type==='1'">Ah2>
    <h2 v-else-if="type==='2'">Bh2>
    <h2 v-else>Ch2>
div>
body>
<script>
    let vm = new Vue({
        el: '#box',
        data: {
            type: '1',
        }
    })
script>
html>

vue