You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 18中Swiper.js本地正常,部署至Vercel后样式失效

Angular 18 集成 Swiper.js 部署Vercel后样式失效问题

我在Angular 18组件中使用Swiper.js实现证书轮播,本地通过npm start运行时渲染正常,但部署至Vercel(通过Vercel网页端而非CLI部署)后样式完全崩溃:幻灯片垂直堆叠、导航按钮消失、容器丢失尺寸。

我通过npm引入Swiper,已检查控制台确认Swiper已初始化,尝试将import 'swiper/scss'替换为import 'swiper/css',也手动安装了Sass,但均无效果。

我的GitHub仓库:https://github.com/moppdev/personal-portfolio

组件TS代码

import { Component, inject, OnInit } from '@angular/core';
import { InfoService } from '../services/info.service';
import { Education, Certification } from '../model/education.model';
import { CardComponent } from "./card/card.component";
import { Swiper } from 'swiper';
import { Navigation } from 'swiper/modules';
import { SwiperOptions } from 'swiper/types';
import 'swiper/scss';
import 'swiper/scss/navigation';
import { ErrorSuccessCardComponent } from "../error-success-card/error-success-card.component";

@Component({
  selector: 'app-education',
  standalone: true,
  imports: [CardComponent, ErrorSuccessCardComponent],
  templateUrl: './education.component.html',
  styleUrl: './education.component.scss'
})
export class EducationComponent implements OnInit {
  checker: boolean = false;
  errorMessage: string = "";
  
  education?: Education[];
  certifications?: Certification[];

  private infoService = inject(InfoService);

  ngOnInit()
  {
    try {
      this.education = this.infoService.education;
      this.certifications = this.infoService.certifications;  
      this.checker = true;

      setTimeout(() => {
        const certSwiperOptions: SwiperOptions = {
          modules: [Navigation],
          direction: 'horizontal',
          spaceBetween: 20,
          navigation: {
            prevEl: ".swiper-button-prev",
            nextEl: ".swiper-button-next"
          },
          breakpoints: {
            480: {
              slidesPerView: 2,
            },
            1100: {
              slidesPerView: 3,
            }
          }
        };

        const certSwiper = new Swiper(".cert-swiper", certSwiperOptions);
        console.log(certSwiper);
      }, 100);
      
    } catch (error) {
      this.errorMessage = "Something went wrong with retrieving information from the JSON file.";
      throw new Error(`${error}`);
    }
  }
}

效果对比

  • 预期显示效果:示例:预期显示效果
  • 实际显示效果:实际显示问题

内容的提问来源于stack exchange,提问作者PrimeBeat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:05:24