vue v-if和v-show区别
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<p v-if="ifShow">{{ message }}</p>
<p v-show="ifShow">{{ furong }}</p>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'Hello Vue.js!',
furong: 'Hello furong!',
ifShow: true,
},
})
</script>
</body>
</html>
总结
当显示和隐藏切换频繁时,使用v-show
当只有一次切换时,使用v-if