当前位置: 首页 > 编程笔记 >

Angular6中使用Swiper的方法示例

孔斌
2023-03-14
本文向大家介绍Angular6中使用Swiper的方法示例,包括了Angular6中使用Swiper的方法示例的使用技巧和注意事项,需要的朋友参考一下

项目使用的Angular版本是V6.0.3


安装Swiper

npm install swiper --save

或者

yarn add swiper --save

在angular.json文件添加swiper.js和swiper.css

angular.json

安装模组定义档

npm install @types/swiper --save

或者

yarn add @types/swiper --save

配置tsconfig文件

tsconfig.json

tsconfig.app.json

按照上面的配置完成后,angular里就可以用swiper。下面是一个小demo。

test.component.html

<div class="swiper-container">
  <div class="swiper-wrapper">
    <div class="swiper-slide" *ngFor="let data of slides">
      <img [src]="data" alt="" width="100%">
    </div>
  </div>
  <!-- 如果需要分页器 -->
  <div class="swiper-pagination"></div>

  <!-- 如果需要导航按钮 -->
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>
</div>

test.component.ts

import {
  AfterViewInit,
  Component,
  OnInit
} from '@angular/core';

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html'
})
export class TestComponent implements AfterViewInit {
  testSwiper: Swiper;
  slides = [
    'https://via.placeholder.com/300x200/FF5733/ffffff',
    'https://via.placeholder.com/300x200/C70039/ffffff',
    'https://via.placeholder.com/300x200/900C3F/ffffff'
  ];

  constructor() {}

  ngAfterViewInit() {
    this.testSwiper = new Swiper('.swiper-container', {
      direction: 'horizontal',
      loop: true,
      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
      },
      // 如果需要前进后退按钮
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
      // 如果需要滚动条
      scrollbar: {
        el: '.swiper-scrollbar',
      },
    });
  }
}

运行结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。

 类似资料:
  • 本文向大家介绍Vue框架里使用Swiper的方法示例,包括了Vue框架里使用Swiper的方法示例的使用技巧和注意事项,需要的朋友参考一下 下载swiper 首先使用npm 或者cnpm下载swiper 引入swiper 使用swiper mounted里面调用 注意 如果想要从后台请求图片放上去 new Swiper要写在网络请求成功的函数里面,否则不会出来数据。 slider组件的内容如下:

  • 本文向大家介绍angular6.x中ngTemplateOutlet指令的使用示例,包括了angular6.x中ngTemplateOutlet指令的使用示例的使用技巧和注意事项,需要的朋友参考一下 在使用angular进行开发的时候,通过属性绑定向组件内部传值的方式,有时候并不能完全满足需求,比如我们写了一个公共组件,但是某个模板使用这个公共组件的时候,需要在其内部添加一些标签内容,这种情况下,

  • 本文向大家介绍解决vue中使用swiper插件问题及swiper在vue中的用法,包括了解决vue中使用swiper插件问题及swiper在vue中的用法的使用技巧和注意事项,需要的朋友参考一下 Swiper简介 Swiper常用于移动端网站的内容触摸滑动。 Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。 Swiper能实现触屏焦点图、触屏Tab切换、触屏多

  • 本文向大家介绍vue 中swiper的使用教程,包括了vue 中swiper的使用教程的使用技巧和注意事项,需要的朋友参考一下 Install 在vue cli下的使用 npm install vue-awesome-swiper --save 在main.js中 在component.vue中 参考:https://github.com/surmon-china/vue-awesome-swip

  • 本文向大家介绍SpringBoot 中使用JSP的方法示例,包括了SpringBoot 中使用JSP的方法示例的使用技巧和注意事项,需要的朋友参考一下 本文介绍了SpringBoot 中使用JSP的方法示例,分享给大家,具体如下: 依赖: 示例代码: 在SpringBoot中使用JSP SpringBoot默认不支持JSP,需要在项目中添加相关的依赖 配置文件增加配置项: Login.java 以

  • 本文向大家介绍在Golang中使用Redis的方法示例,包括了在Golang中使用Redis的方法示例的使用技巧和注意事项,需要的朋友参考一下 周五上班的主要任务是在公司老平台上用redis处理一个队列问题,顺便复习了一下redis操作的基础知识,回来后就想着在自己的博客demo里,用redis来优化一些使用场景,学习一下golang开发下redis的使用。 Redis简单介绍 简介 关于Redi