vue.js顯示與隱藏(v-if)

_code小學生發表於2018-03-24
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- Vue.js -->
    <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
</head>
<body>
<div id="app">
    <p v-if="show">顯示這段文字</p>
</div>
</body>
</html>
<script>
    //當資料show的值為true時,p元素會被插入,為false時會被移除
    var myData = {
        show:true
    };
    var app = new Vue({
        el:'#app',
        data:myData,
    })
</script>

相關文章