HTML代码:

<div id="app">
  <h1>Task List</h1>
  <div v-for="(task, index) in tasks" :key="index" :class="{'reminder task': task.reminder, 'task': !task.reminder}">
    <h3>{{ task.text }}</h3>
    <p>{{ task.day }}</p>
  </div>
</div>

Vue实例代码:

new Vue({
  el: '#app',
  data: {
    tasks: []
  },
  created() {
    //在Vue实例创建结束的钩子函数中赋值
    this.tasks = [
      {
        id: 1,
        text: 'Buy groceries',
        day: 'Monday, 9am',
        reminder: true
      },
      {
        id: 2,
        text: 'Doctor appointment',
        day: 'Tuesday, 2pm',
        reminder: true
      },
      {
        id: 3,
        text: 'Finish project',
        day: 'Friday, 5pm',
        reminder: false
      }
    ]
  }
})

标签: 科技


原文地址: https://gggwd.com/t/topic/beo9 著作权归作者所有。请勿转载和采集!