v-else-if 要紧跟 v-if
v-else要紧跟v-else-if 或 v-if
代码:
<!doctype html>
<html lang="en">
<head><meta charset="UTF-8"><title>vue.js v-if语法使用 </title><script src="vue.js"></script><script src="node_modules/axios/dist/axios.js"></script><script src="node_modules/lodash/lodash.js"></script>
</head>
<body>
<div id="ask"><!--vue不能控制body和html的标签--><input type="text" v-model="age"><span v-if="age<20">小孩</span><span v-else-if="age<30">青年</span><span v-else-if="age<40">中年</span><span v-else>老年</span><hr><input type="checkbox" v-model="copyright"> 接受协议<span v-if="!copyright">请先接受协议</span><button v-else>注册</button>
</div>
<script>var app = new Vue({ //实例化vueel:'#ask',//vue控制id为ask的元素,data:{age:0,copyright:false},});
</script>
</body>
</html>