Vue.js 任务列表:使用 v-for 指令实现动态加载和样式绑定
<div id="app">
<h2>任务列表</h2>
<div v-for="(task, index) in tasks" :key="index" :class="{'reminder task': task.reminder, 'task': !task.reminder}">
{{ task.title }}
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
tasks: []
},
created() {
// 使用axios获取数据
axios.get('tasks.json')
.then(response => {
this.tasks = response.data;
})
.catch(error => {
console.log(error);
});
}
});
</script>
原文地址: https://www.cveoy.top/t/topic/mFft 著作权归作者所有。请勿转载和采集!