首页闪屏修复

This commit is contained in:
WindowBird 2025-10-16 09:38:26 +08:00
parent 18e3f0f987
commit cc40ecd35d
2 changed files with 31 additions and 42 deletions

View File

@ -4,49 +4,9 @@ import {
iotSolutionsData,
multiScenarioData,
softwareDevelopmentData,
smartHardwareData,
pageConfig
smartHardwareData
} from '~/data/indexData'
//
const loadResources = () => {
// CSS
pageConfig.cssFiles.forEach(href => {
if (!document.querySelector(`link[href="${href}"]`)) {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = href
link.type = 'text/css'
document.head.appendChild(link)
}
})
// JS
pageConfig.jsFiles.forEach(src => {
if (!document.querySelector(`script[src="${src}"]`)) {
const script = document.createElement('script')
script.src = src
script.type = 'text/javascript'
document.head.appendChild(script)
}
})
// favicon
if (!document.querySelector('link[rel="shortcut icon"]')) {
const link = document.createElement('link')
link.rel = 'shortcut icon'
link.href = pageConfig.favicon
document.head.appendChild(link)
}
//
const protocol = window.location.protocol === 'https:' ? 'https://' : 'http://'
const script = document.createElement('script')
script.src = `${protocol}hm.baidu.com/h.js?${pageConfig.baiduAnalytics}`
script.type = 'text/javascript'
document.head.appendChild(script)
}
//
const handleAnchorLinks = () => {
if (window.location.hash) {
@ -86,7 +46,6 @@ const handleDropdownImageHover = (index: number) => {
}
onMounted(() => {
loadResources()
handleAnchorLinks()
//

View File

@ -1,4 +1,34 @@
<script lang="ts" setup>
import {useHead} from "#app";
import {pageConfig} from "~/data/indexData";
// 使 Nuxt 3 useHead
useHead({
link: [
{rel: 'stylesheet', href: '/css/bootstrap.min.css'},
{rel: 'stylesheet', href: '/css/main2.css'},
{rel: 'stylesheet', href: '/css/main.css'},
{rel: 'stylesheet', href: '/css/yuxi2019.css'},
{rel: 'shortcut icon', href: pageConfig.favicon}
],
script: [
{src: '/js/index.js'},
{src: '/js/gopcOm.js'},
{
innerHTML: `
var _hmt = _hmt || [];
(function() {
var protocol = window.location.protocol === 'https:' ? 'https://' : 'http://';
var hm = document.createElement("script");
hm.src = protocol + "hm.baidu.com/h.js?${pageConfig.baiduAnalytics}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
`
}
]
})
</script>
<template>