JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<h1 style="text-align: center;">JavaScript 系列七:第4課 ── 學習 Vue 迴圈的寫法</h1>
<div id="app">
<!-- 在vue裡,for in用法 === for of,但原生JS並非如此 -->
<div class="note" v-for="note of notes" :style="{ color: note.color ,'border-color': note.color }">
<h3 class="title">{{ note.title }}</h3>
<p class="content">{{ note.content }}</p>
</div>
</div>
CSS
* {
padding: 0;
margin: 0;
}
#app {
display: flex;
justify-content: space-around;
}
.note {
margin: 20px 0;
border: 1px solid #ccc;
width: 30%;
padding: 20px;
box-sizing: border-box;
text-align: center;
}
JavaScript
const { createApp } = Vue;
createApp({
data() {
return {
notes: [
{
title: "春節行程安排",
content: "吃飽睡,睡飽吃",
color: "red"
},
{
title: "工作待辦事項",
content: "詢問各家廠商報價",
color: "green"
},
{
title: "運動健身計畫",
content: "每天早上六點去健身",
color: "blue"
}
]
};
},
mounted() {
this.notes[0].content = "多出門、到處走走、也要多運動";
}
}).mount("#app");