<template> <div class="hello"> <div class="top">這裏是首頁</div> <button @click="addItem">增長</button> <ul> <li v-for="g in list"> <span>{{g.mm}}</span>** <span>{{g.price}}</span> </li> </ul> </div> </template> <script> export default { name: 'hello', data () { return { name: 'Welcome to Your Vue.js App', list: [ {mm: '路飛', price: 50}, {mm: '娜美', price: 20}, {mm: '喬巴', price: 5}, {mm: '索隆', price: 45} ] } }, methods: { addItem () { // 這裏對數據進行操做 this.list.push({mm: '白鬍子', price: 80}) } } }</script> <style scoped>h1, h2 { font-weight: normal; } ul { list-style-type: none; padding: 0; } li { margin: 0 10px; } a { color: #42b983; } .top { margin: auto; width: 200px; height: 100px; background: #f56868; }</style>
效果如圖html