From 54cfcc2f989e8be9f01792c0eb697d85521f8690 Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Tue, 21 Oct 2025 10:28:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E9=A1=B5=E9=9D=A2=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E5=8E=BB=E9=99=A4=E6=9C=AA=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E9=97=AA=E7=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/news/new.vue | 79 +++++++++++------------------------ app/layouts/no-navigation.vue | 4 +- app/pages/articles.vue | 46 ++++++++++++-------- 3 files changed, 54 insertions(+), 75 deletions(-) diff --git a/app/components/news/new.vue b/app/components/news/new.vue index 9116a66..1443a3f 100644 --- a/app/components/news/new.vue +++ b/app/components/news/new.vue @@ -71,64 +71,33 @@ const {initImageStyles} = useImageStyles( } ) -onMounted(() => { - // 只在客户端执行 - if (typeof window !== 'undefined') { - // 加载CSS样式文件 - loadCSSFiles() +// 使用 Nuxt 的 useHead 来管理页面资源 +useHead({ + title: computed(() => articleData.value?.title ? `${articleData.value.title} - 创特科技` : '文章详情 - 创特科技'), + meta: [ + { + name: 'description', + content: computed(() => articleData.value?.content ? articleData.value.content.substring(0, 160) + '...' : '创特科技专业文章') + }, + {name: 'keywords', content: '创特科技,技术文章,共享单车,软件开发,解决方案'} + ], + link: [ + {rel: 'stylesheet', href: '/news/bootstrap.min.css'}, + {rel: 'stylesheet', href: '/news/main22.css'}, + {rel: 'stylesheet', href: '/news/new_index.css'}, + {rel: 'stylesheet', href: '/news/float.css'}, + {rel: 'stylesheet', href: '/news/animate.min.css'} + ], + script: [ - // 加载JavaScript文件 - loadJSFiles() - } + {src: '/news/float.js', defer: true} + ] }) -// 初始化图片样式处理 -initImageStyles() - -const loadJSFiles = () => { - if (typeof document === 'undefined') return - - const jsFiles = [ - '/news/jquery.1.11.3.min.js', - '/news/bootstrap.min.js', - '/news/float.js', - ] - - jsFiles.forEach(src => { - // 检查是否已经加载过该JS文件 - const existingScript = document.querySelector(`script[src="${src}"]`) - if (!existingScript) { - const script = document.createElement('script') - script.src = src - script.type = 'text/javascript' - document.head.appendChild(script) - } - }) -} - -const loadCSSFiles = () => { - if (typeof document === 'undefined') return - - const cssFiles = [ - '/news/bootstrap.min.css', - '/news/main22.css', - '/news/new_index.css', - '/news/float.css', - '/news/animate.min.css' - ] - - cssFiles.forEach(href => { - // 检查是否已经加载过该CSS文件 - const existingLink = document.querySelector(`link[href="${href}"]`) - if (!existingLink) { - const link = document.createElement('link') - link.rel = 'stylesheet' - link.href = href - link.type = 'text/css' - document.head.appendChild(link) - } - }) -} +onMounted(() => { + // 初始化图片样式处理 + initImageStyles() +})