렌더할 때마다 비동기통신하는 부분 수정
This commit is contained in:
29
src/index.js
29
src/index.js
@@ -107,27 +107,28 @@ const router = (path) => {
|
|||||||
return matched.route.view;
|
return matched.route.view;
|
||||||
};
|
};
|
||||||
|
|
||||||
const render = async (path) => {
|
const render = (path) => {
|
||||||
const app = document.getElementById('app');
|
const app = document.getElementById('app');
|
||||||
|
|
||||||
try {
|
app.innerHTML = `
|
||||||
await fetchContents();
|
${Header()}
|
||||||
|
${router(path)}
|
||||||
|
${Footer()}
|
||||||
|
`;
|
||||||
|
|
||||||
app.innerHTML = `
|
console.log('render!');
|
||||||
${Header()}
|
|
||||||
${router(path)}
|
|
||||||
${Footer()}
|
|
||||||
`;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function init() {
|
const init = async () => {
|
||||||
|
await fetchContents();
|
||||||
render('/');
|
render('/');
|
||||||
// 셀렉터를 #app으로 했기 때문에 함수 순서가 바뀌어도 동작한다.
|
// 셀렉터를 #app으로 했기 때문에 함수 순서가 바뀌어도 동작한다.
|
||||||
navigateTo('#app');
|
navigateTo('#app');
|
||||||
console.log('init 완료 🚀');
|
console.log('init 완료 🚀');
|
||||||
}
|
};
|
||||||
|
|
||||||
init();
|
try {
|
||||||
|
init();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user