pinked

导航

[vue]判断与循环

判断与循环

if判断

<div id="app">
    <h1 v-if="type==='A'">aaaaa</h1>
    <h1 v-else-if="type==='B'">bbbbb</h1>
    <h1 v-else>ccccc</h1>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            type: 'B'
        }
    });
</script>

for循环

<div id="app">
    <li v-for="item in fruits">
        {{item.message}}
    </li>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
<script>
    var vm = new Vue({
        el: "#app",
        data: {
            fruits: [
                {message: '苹果'},
                {message: '香蕉'},
                {message: '菠萝'}
            ]
        }
    });
</script>

posted on 2020-02-15 01:08  pinked  阅读(203)  评论(0编辑  收藏  举报