Files
2026-03-26 21:45:32 +08:00

30 lines
725 B
JavaScript

new Vue({
el: "#app",
data: {
keyword: "",
courses: [
{ id: 1, title: "Vue 实例入门" },
{ id: 2, title: "Vue 指令系统" },
{ id: 3, title: "组件通信实战" },
],
},
computed: {
filteredCourses() {
// 任务:返回过滤后的课程列表
const value = this.keyword.trim().toUpperCase()
return this.courses.filter(item => item.title.toUpperCase().includes(value))
},
matchedCount() {
// 任务:返回 filteredCourses 的数量
return this.filteredCourses.length;
},
},
watch: {
keyword(newValue) {
// 任务:在控制台输出关键字变化
console.log(`筛选关键词:${newValue}`);
},
},
});