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

v-for指令

title log post pre name sco lang src lan

<!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> </ul> </div> <script src="../lib/vue.js"></script> <script src="js/main.js"></script> </body> </html>
var app = new Vue({
    el:"#app",
    data:{
        // foodList:["蔥","姜","蒜"],
        foodList:[
            {
                name:"蔥",
                price:10,
                discount:.8
            },
            {
                name:"姜",
                price:8,
                discount:.6
            },
            {
                name:"蒜",
                price:6,

            }
        ]
    }
})

v-for指令