此篇為簡化過程摘要
Page Component @/pages
<template>
{{ title }} <!-- 2 -->
</template>
<script>
export default {
/* Both */
data() {
return { title: 1 };
},
/* Server, Nuxt Hooks */
asyncData ({ params }, callback) {
callback(null, { title: 2 })
},
fetch() {},
layout: 'front',
/* Client, Vue Hooks */
mounted() {
console.info(this.title); /* 1 */
},
}
</script>
跟 General Component 差在哪?
包含 /components/*.vue
、/layouts/*.vue
一般 Vue File 寫法,無擴充屬性
<script>
export default {
/* Both */
data() {
return { title: 1 };
},
/* Server, Nuxt Hooks 從缺 */
/*
asyncData ({ params }, callback) {
callback(null, { title: 2 })
},
fetch() {},
layout: 'front',
*/
/* Client, Vue Hooks */
mounted() {
console.info(this.title, this);
},
}
</script>
Page Component 該怎麼拆?
/layouts
/components
props
甜點電商拆的順序則是
/layouts/front.vue
/components
,Header
、Footer
asyncData
、fetch
,透過 props
傳給 component