条件渲染
指令 | 释义 |
---|---|
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、else</title> <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、else</h3> <h2 v-if="type==='1'">A</h2> <h2 v-else-if="type==='2'">B</h2> <h2 v-else>C</h2> </div> </body> <script> let vm = new Vue({ el: '#box', data: { type: '1', } }) </script> </html>