1. 程式人生 > >Vue:v-for指令

Vue:v-for指令

-1 color ges png lan img ood utf food

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="food in foodList">{{food.name}}:¥{{food.discount ? food.price * food.discount : food.price}}</li> //如果discount存在則輸出price *     
                                                                        discount,否則輸出price
    
</ul> </div> <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script> <script> var app=new Vue({ el:"#app", data:{ foodList:[{name:"蔥",price:10,discount:0.5}, {name:"姜",price:8,discount:0.6}, {name:"辣椒",price:7}] } })
</script> </body> </html>

技術分享

Vue:v-for指令