- Introduced Vue3 exercises covering composable API, reactivity, lifecycle hooks, and built-in components. - Added structured interview plan for frontend candidates focusing on HTML, CSS, JavaScript, TypeScript, and Vue. - Included starter files for each exercise and detailed README documentation for guidance.
39 lines
683 B
JavaScript
39 lines
683 B
JavaScript
const { createApp, ref, onMounted } = Vue;
|
|
|
|
function useCourses() {
|
|
const courses = ref([]);
|
|
const loading = ref(true);
|
|
const error = ref("");
|
|
|
|
async function loadCourses() {
|
|
// 任务:
|
|
// 1. 模拟异步请求
|
|
// 2. 成功时给 courses 赋值
|
|
// 3. 失败时给 error 赋值
|
|
// 4. 最后把 loading 设为 false
|
|
}
|
|
|
|
return {
|
|
courses,
|
|
loading,
|
|
error,
|
|
loadCourses,
|
|
};
|
|
}
|
|
|
|
createApp({
|
|
setup() {
|
|
const { courses, loading, error, loadCourses } = useCourses();
|
|
|
|
onMounted(() => {
|
|
// 任务:页面挂载后调用 loadCourses
|
|
});
|
|
|
|
return {
|
|
courses,
|
|
loading,
|
|
error,
|
|
};
|
|
},
|
|
}).mount("#app");
|