照片浏览器 Vue 组件

照片浏览器是一款照片浏览器组件,用于显示一系列照片 / 图像。可以对照片进行放大和拖动(可选)。

照片浏览器 Vue 组件代表 Framework7 的 照片浏览器 组件。

照片浏览器 Vue 组件不呈现任何输出。它可用于创建 JS 照片浏览器实例,并在 Vue 组件中对其进行控制。

照片浏览器组件

包含以下组件

照片浏览器属性

你可以将所有参数传递到单个 params 属性中,或为每个参数使用单独的 props,以通过组件属性指定它们

PropTypeDefaultDescription
<f7-photo-browser> 属性
initbooleantrue初始化 Photo Browser
paramsObject具有 Photo Browser 参数 的对象
photosarray[]包含照片 URL 的数组或包含“url”(或“html”)和“caption”属性的对象数组
thumbsarray[]array
缩略图图像 URL 数组。如果未指定或空数组,将不会呈现缩略图urlstringphotos/
将被设置为当前路由的 Photo Browser 模态 URLbooleanfalse将打开的 Photo Browser 添加到路由器历史记录中,这提供了通过在路由器历史记录中返回并设置当前路由到 Photo Browser 模态来关闭 Photo Browser 的功能
swiperobject具有 Swiper 参数的对象。默认情况下等于
swiper: {
  initialSlide: 0,
  spaceBetween: 20,
  speed: 300,
  loop: false,
  preloadImages: true,
  keyboard: {
    enabled: true,
  },
  navigation: {
    nextEl: '.photo-browser-next',
    prevEl: '.photo-browser-prev',
  },
  zoom: {
    enabled: true,
    maxRatio: 3,
    minRatio: 1,
  },
  lazy: {
    enabled: true,
  },
},
virtual-slidesbooleantrue启用后,Swiper 将使用 Virtual Slides
close-by-backdrop-clickbooleantrue启用后,点击背景时将关闭 Photo Browser 弹窗
expositionbooleantrue点击 Photo Browser 时启用禁用展示模式
exposition-hide-captionsbooleanfalse如果你还想在展示模式下隐藏标题,请将其设置为 true
swipe-to-closebooleantrue启用此参数后,你可以通过向上/向下滑动来关闭 Photo Browser
typeurlstandalone定义如何打开 Photo Browser。可以是 standalone(将以叠加方式打开,带有自定义过渡效果)、popup(将以弹窗形式打开)、page(将注入到 View 中并作为新页面加载)
themeurllightPhoto Browser 配色主题,可以是 lightdark
captions-themeurl标题配色主题,也可以是 darklight。默认情况下,等于“theme”参数
navbarbooleantrue设置为 false 以移除 Photo Browser 的导航栏
toolbarbooleantrue设置为 false 以移除 Photo Browser 的工具栏
page-back-link-texturlBackPhoto Browser 导航栏中的返回链接文本
popup-close-link-texturlClose以 Popup 或 Standalone 方式打开时,Photo Browser 导航栏中的关闭链接文本
navbar-show-countbooleanundefined定义是否在导航栏标题中显示“3 of 5”文本。如果不指定(未定义),则当项目数超过 1 时,它将显示此文本
navbar-of-texturlof照片计数器中“of”的文本:“3 of 5”
icons-colorurl默认颜色之一

Photo Browser 事件

事件Description
<f7-photo-browser>事件
photobrowser:open光浏览器打开时触发事件。
photobrowser:opened光浏览器完成其打开动画后触发事件
photobrowser:close光浏览器关闭时触发事件。
photobrowser:closed光浏览器完成其关闭动画后触发事件
photobrowser:swipetoclose当用户通过上下滑动关闭光浏览器时,会触发此事件。

光浏览器方法

以下光浏览器组件方法可用(例如通过$refs访问它)

<f7-photo-browser>方法
.open(index)在照片上打开光浏览器,图片索引号等于"index"参数。如果未指定"index"参数,它将在上次关闭的照片上打开。
.close()关闭光浏览器
.expositionToggle()切换显露模式
.expositionEnable()启用显露模式
.expositionDisable()禁用显露模式

示例

photo-browser.vue
<template>
  <f7-page>
    <f7-navbar title="Photo Browser"></f7-navbar>
    <f7-block strong-ios outline-ios>
      <p>
        Photo Browser is a standalone and highly configurable component that allows to open window
        with photo viewer and navigation elements with the following features:
      </p>
      <ul>
        <li>Swiper between photos</li>
        <li>Multi-gestures support for zooming</li>
        <li>Toggle zoom by double tap on photo</li>
        <li>Single click on photo to toggle Exposition mode</li>
      </ul>
    </f7-block>
    <f7-block strong-ios outline-ios>
      <p>
        Photo Browser could be opened in a three ways - as a Standalone component (Popup
        modification), in Popup, and as separate Page:
      </p>
      <div class="grid grid-cols-3 grid-gap">
        <div>
          <f7-photo-browser ref="standalone" :photos="photos" :thumbs="thumbs" />
          <f7-button fill @click="$refs.standalone.open()">Standalone</f7-button>
        </div>
        <div>
          <f7-photo-browser ref="popup" :photos="photos" :thumbs="thumbs" type="popup" />
          <f7-button fill @click="$refs.popup.open()">Popup</f7-button>
        </div>
        <div>
          <f7-photo-browser
            ref="page"
            :photos="photos"
            :thumbs="thumbs"
            type="page"
            page-back-link-text="Back"
          />
          <f7-button fill @click="$refs.page.open()">Page</f7-button>
        </div>
      </div>
    </f7-block>
    <f7-block strong-ios outline-ios>
      <p>
        Photo Browser supports 2 default themes - default Light (like in previous examples) and Dark
        theme. Here is a Dark theme examples:
      </p>
      <div class="grid grid-cols-3 grid-gap">
        <div>
          <f7-photo-browser ref="standaloneDark" :photos="photos" :thumbs="thumbs" theme="dark" />
          <f7-button fill @click="$refs.standaloneDark.open()">Standalone</f7-button>
        </div>
        <div>
          <f7-photo-browser
            ref="popupDark"
            :photos="photos"
            :thumbs="thumbs"
            theme="dark"
            type="popup"
          />
          <f7-button fill @click="$refs.popupDark.open()">Popup</f7-button>
        </div>
        <div>
          <f7-photo-browser
            ref="pageDark"
            :photos="photos"
            :thumbs="thumbs"
            theme="dark"
            type="page"
            page-back-link-text="Back"
          />
          <f7-button fill @click="$refs.pageDark.open()">Page</f7-button>
        </div>
      </div>
    </f7-block>
  </f7-page>
</template>
<script>
import { f7Navbar, f7Page, f7PhotoBrowser, f7Block, f7Button } from 'framework7-vue';

export default {
  components: {
    f7Navbar,
    f7Page,
    f7PhotoBrowser,
    f7Block,
    f7Button,
  },
  data() {
    return {
      photos: [
        {
          url: 'img/beach.jpg',
          caption: 'Amazing beach in Goa, India',
        },
        'http://placekitten.com/1024/1024',
        'img/lock.jpg',
        {
          url: 'img/monkey.jpg',
          caption: 'I met this monkey in Chinese mountains',
        },
        {
          url: 'img/mountains.jpg',
          caption: 'Beautiful mountains in Zhangjiajie, China',
        },
      ],
      thumbs: [
        'img/beach.jpg',
        'http://placekitten.com/1024/1024',
        'img/lock.jpg',
        'img/monkey.jpg',
        'img/mountains.jpg',
      ],
    };
  },
};
</script>