判断与循环
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/[email protected]/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/[email protected]/dist/vue.min.js"></script>
<script>
var vm = new Vue({
el: "#app",
data: {
fruits: [
{message: '苹果'},
{message: '香蕉'},
{message: '菠萝'}
]
}
});
</script>
原文地址:https://www.cnblogs.com/pinked/p/12310437.html
时间: 2024-10-17 12:17:52