1.v-if指令的作用是:根据表达式的真假切换元素的显示状态
2.本质是通过操纵dom元素来切换显示状态
3.表达式的值为true,元素存在于dom树中,为false,从dom树中移除
4.频繁的切换使用v-show,反之使用v-if,前者的切换消耗小
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <div id="app"> <input type="button" value="切换状态" @click="changeShow"> <h1 v-show="isshow">Web前端</h1> <h2 v-if="isshow">Web前端</h2> <h3 v-if="temperature>=35">热死了</h3> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> var app=new Vue({ el:"#app", data:{ isshow:false, temperature:40 }, methods:{ changeShow:function(){ this.isshow=!this.isshow; } } }) </script> </body> </html>