11_条件渲染
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!-- 引入vuejs文件 -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<!--
备注:使用
v-if的元素可能无法获取到,而使用v-show一定可以获取到。
-->
<body>
<!-- 准备好一个容器 -->
<div id="root">
<!-- 使用v-show做条件渲染 -->
<!-- <h2 v-show="false">欢迎来到{{name}}</h2> -->
<!-- <h2 v-show="1===1">欢迎来到{{name}}</h2> -->
<!-- 使用v-if做条件渲染 -->
<!-- <h2 v-if="false">欢迎来到{{name}}0</h2>
<h2 v-if="1===1">欢迎来到{{name}}1</h2>
<h2 v-else-if="1===1">欢迎来到{{name}}2</h2>
<h2 v-else>欢迎来到{{name}}3</h2>
-->
<!-- template不影响结构 只能配合v-if使用 -->
<template v-if="1===1">
<h2>北京</h2>
<h2>上海</h2>
<h2>深圳</h2>
</template>
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false;
new Vue({
el: "#root",
data: {
name: "vue",
},
});
</script>
</html>