Vue —— 元素显示

  • v-show
标记是否显示html元素 (注意:v-show设置的标记在html DOM中不会消失)
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>show.html</title>
    <script src="../js/vue.js"></script>
    <link type='text/css' rel='styleSheet' href='../css/style.css' >
</head>
   
<body>
    <div id="example">
        <!-- v-show:要不要显示该标签,消失后连位置都空出来 -->
        <h2 v-show="result">{{message}}</h2>
        <button @click="btnclick()">改变</button>
    </div>
</body>
<script>
    new Vue( {
        el: "#example",
        data: {
            message: "我在这呢",
            result: true
        },
        methods: {
            btnclick: function() {
                //可以直接感叹号取反
                this.result = !this.result;
            }
        }
    });
</script>
</html>

 

posted @ 2020-10-24 09:35  a最简单  阅读(440)  评论(0)    收藏  举报