Skip to content

Daily Plan

更新: 5/3/2025 字数: 0 字 时长: 0 分钟

#todo

  • [ ]
  • [ ]

Daily Study

更新: 5/3/2025 字数: 0 字 时长: 0 分钟

博客配置遇到的问题

彩虹背景动画没有正确加载到对应的路由页面,原先代码如下:

js
    if (typeof window !== 'undefined') {
      watch(
        () => router.route.data.relativePath,
        () => updateHomePageStyle(location.pathname === '/'),
        { immediate: true },
      )
    }

此时存在问题,当我设置的base路由为'/blog/'时,路由的data.relativePath为'/blog/index.html',而不是'/index.html',导致watch监听不到变化。 解决方案

js
    if (typeof window !== 'undefined') {
      watch(
        // 监听路由对象的 path 变化更可靠
        () => router.route.path, 
        (newPath) => { 
          // console.log('Current route path:', newPath); // 添加日志方便调试
          // console.log('Current location.pathname:', location.pathname); // 添加日志方便调试
          // console.log('Current relativePath:', router.route.data.relativePath); // 添加日志方便调试
          updateHomePageStyle(newPath === '/Blog/'); // 使用 router.route.path 判断
        },
        { immediate: true },
      )
    }

Daily Problem

更新: 5/3/2025 字数: 0 字 时长: 0 分钟

菜就多练

本站访客数 人次 本站总访问量