vueJS简单的点击显示与隐藏的效果

目前前端框架太多,接触过angular、ember,现在开始倒腾vue

此处用到v-if、v-else、v-show,v-if或让元素不在DOM上,v-show只是改变display:block属性,感觉v-if好

感觉跟适合、

演示效果:http://wjf444128852.github.io/demo/myVue/demo/demo9.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>v-if、v-else、v-show</title>
    <script src="../js/vue.js"></script>
    <!--copy from http://vuejs.org.cn/guide/-->
</head>
<body>
    <div id="app">
        <p v-if="willShow">显示显示显示</p>
        <p v-else>隐藏隐藏隐藏隐藏</p>
        <button @click="fn()">改变</button>
    </div>
    <script>
        var vm=new Vue({
            el:"#app",
            data:{
                willShow:true
            },
            methods:{
                fn:function(){
                    if(this.willShow==true){
                        this.willShow=false;
                    }else{
                        this.willShow=true
                    }
                }
            }
        });
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/-walker/p/5442723.html