const menuData = [
{ text: "ぐりりキャラバン", link: "caravan.html" },
{ text: "ぐりり絵本", link: "ehon.html" },
{ text: "子育て応援", link: "kosodate.html" },
{ text: "フードバンク支援", link: "foodbank.html" },
{ text: "会社見学", link: "https://www.khb-tv.co.jp/syanai-kengaku/" },
{ text: "番組・イベント", link: "other.html" },
{ text: "ぐりりピアノ", link: "piano.html" },
{ text: "ぐりり募金", link: "https://www.khb-tv.co.jp/guriribokin/" }
];
Vue.createApp({
components: {
"header-component": {
template: `
`,
data() {
return {
isOpen: false,
menuItems: menuData,
isTopPage: window.location.pathname.endsWith("index.html") || window.location.pathname === "/"
};
},
computed: {
computedMenuItems() {
return this.menuItems.map(item => {
if (item.link.startsWith("#")) {
return {
...item,
link: this.isTopPage ? item.link : "index.html" + item.link
};
}
return item;
});
}
},
methods: {
toggleMenu() {
this.isOpen = !this.isOpen;
},
closeMenu() {
this.isOpen = false;
},
handleClick(link) {
if (this.isTopPage && link.startsWith("#")) {
const target = document.querySelector(link);
if (target) {
window.scrollTo({ top: target.offsetTop, behavior: "smooth" });
}
} else {
window.location.href = link;
}
}
}
},
"subpage-header": {
props: ["titleSub", "titleJp"],
template: `
`
}
}
}).mount("#app");