页面 Vue 组件

在 Framework7 中,页面与您所想到的网页具有相同的含义。页面是用来显示和操作内容的主要组件。

页面 Vue 组件代表 Framework7 的 页面.

页面组件

以下组件已包含在内

页面属性

属性类型默认值描述
<f7-page> 属性
name字符串页面名称
messages-content布尔值如果在内部使用 消息 组件,则启用此属性以添加所需的额外样式
page-content布尔值true启用时,将在内部自动添加 page-content 元素。在需要为标签使用多个 page-content 元素时,禁用此属性非常有用
tabs布尔值如果使用页面作为 标签 包装器,则启用此属性
login-screen布尔值如果在页面内部使用 登录屏幕,则启用此属性以添加所需的额外样式
no-swipeback布尔值禁用当前页面的滑动返回功能(仅影响 iOS 主题)
with-subnavbar布尔值如果页面内有子导航栏,则启用此属性
no-navbar布尔值如果使用通用导航栏布局,并且需要隐藏通用导航栏(或使用其他导航栏)用于此页面(仅影响 iOS 主题),则启用此属性
no-toolbar布尔值如果使用通用工具栏/标签栏布局,并且需要隐藏工具栏(或使用其他工具栏)用于此页面,则启用此属性
hide-bars-on-scroll布尔值在页面滚动时隐藏导航栏和工具栏
hide-navbar-on-scroll布尔值在页面滚动时隐藏导航栏
hide-toolbar-on-scroll布尔值在页面滚动时隐藏工具栏
ptr布尔值启用 下拉刷新
ptr-distance数字自定义下拉刷新触发距离。默认情况下(如果未指定),为 44px。
ptr-preloader布尔值true如果要使用自定义下拉刷新加载器元素,则禁用此属性
ptr-bottom布尔值false启用从底部下拉刷新
ptr-mousewheel布尔值false启用使用鼠标滚轮下拉刷新(适用于桌面应用)。仅适用于 PTR 顶部
infinite布尔值启用 无限滚动
infinite-top布尔值启用页面顶部的无限滚动
infinite-distance数字触发无限滚动事件的页面底部距离(以 px 为单位)。默认情况下(如果未指定),为 50(px)
infinite-preloader布尔值true如果要使用自定义无限滚动加载器,则禁用此属性
<f7-page-content> 属性
tab布尔值如果使用 page-content 作为标签,则启用此属性
tab-active布尔值如果当前标签处于活动状态,则启用此属性
ptr
ptr-distance
ptr-preloader
ptr-bottom
ptr-mousewheel
infinite
infinite-top
infinite-distance
infinite-preloader
hide-bars-on-scroll
hide-navbar-on-scroll
hide-toolbar-on-scroll
messages-content
login-screen
<f7-page> 属性相同

页面事件

事件描述
<f7-page> 事件
page:mounted当具有 keepAlive 路由的页面被挂载/附加到 DOM 时,将触发此事件
page:init在 Framework7 初始化所需的页面的组件和导航栏后,将触发此事件
page:reinit如果导航到已经初始化的页面,则将触发此事件
page:beforein在完成所有初始化并且页面准备过渡到视图(进入活动/当前位置)时,将触发此事件
page:afterin在页面过渡到视图后,将触发此事件
page:beforeout在页面即将过渡出视图之前,将触发此事件
page:afterout在页面过渡出视图后,将触发此事件
page:beforeunmount当具有 keepAlive 路由的页面即将被卸载/从 DOM 中分离时,将触发此事件
page:beforeremove在页面即将从 DOM 中删除之前,将触发此事件。如果您需要分离一些事件/销毁一些插件以释放内存,则此事件非常有用。此事件不会针对 keepAlive 路由触发。
page:tabshow当页面的父 作为标签的视图 变为可见时,将触发此事件
page:tabhide当页面的父 作为标签的视图 变为隐藏时,将触发此事件
ptr:pullstart当您开始移动下拉刷新内容时,将触发此事件
ptr:pullmove当您移动下拉刷新内容时,将触发此事件
ptr:pullend当您释放下拉刷新内容时,将触发此事件
ptr:refresh当下拉刷新进入“刷新”状态时,将触发此事件
ptr:done在下拉刷新完成后,它将恢复到初始状态(在调用 pullToRefreshDone 方法后),将触发此事件
infinite当页面滚动到达指定(在 data-distance 属性中)的页面底部距离时,将触发此事件。
<f7-page-content> 事件
tab:show当标签变为可见/活动时,将触发此事件
tab:hide当标签变为隐藏/非活动时,将触发此事件
ptr:pullstart
ptr:pullmove
ptr:pullend
ptr:refresh
ptr:done
infinite
<f7-page> 事件相同

页面插槽

页面 Vue 组件 (<f7-page>) 具有用于自定义元素的额外插槽

<f7-page>
  <div slot="fixed">Fixed element</div>
  <p>Page content goes here</p>
</f7-page>

<!-- Renders to: -->

<div class="page">
  <div>Fixed element</div>
  <div class="page-content">
    <p>Page content goes here</p>
  </div>
</div>

示例

无限滚动

infinite-scroll.vue
<template>
  <f7-page
    infinite
    :infinite-distance="50"
    :infinite-preloader="showPreloader"
    @infinite="loadMore"
  >
    <f7-navbar title="Infinite Scroll"></f7-navbar>
    <f7-block-title>Scroll bottom</f7-block-title>
    <f7-list strong-ios outline-ios dividers-ios>
      <f7-list-item
        v-for="(item, index) in items"
        :key="index"
        :title="`Item ${item}`"
      ></f7-list-item>
    </f7-list>
  </f7-page>
</template>
<script>
import { f7Navbar, f7Page, f7BlockTitle, f7List, f7ListItem } from 'framework7-vue';

export default {
  components: {
    f7Navbar,
    f7Page,
    f7BlockTitle,
    f7List,
    f7ListItem,
  },
  data() {
    return {
      items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
      allowInfinite: true,
      showPreloader: true,
    };
  },
  methods: {
    loadMore() {
      const self = this;
      if (!self.allowInfinite) return;
      self.allowInfinite = false;

      setTimeout(() => {
        if (self.items.length >= 200) {
          self.showPreloader = false;
          return;
        }

        const itemsLength = self.items.length;

        for (let i = 1; i <= 20; i += 1) {
          self.items.push(itemsLength + i);
        }

        self.allowInfinite = true;
      }, 1000);
    },
  },
};
</script>

下拉刷新

pull-to-refresh.vue
<template>
  <f7-page ptr :ptr-mousewheel="true" @ptr:refresh="loadMore">
    <f7-navbar title="Pull To Refresh"></f7-navbar>
    <f7-list media-list strong-ios dividers-ios outline-ios>
      <f7-list-item
        v-for="(item, index) in items"
        :key="index"
        :title="item.title"
        :subtitle="item.author"
      >
        <template #media>
          <img :src="item.cover" width="44" style="border-radius: 8px" />
        </template>
      </f7-list-item>

      <f7-block-footer>
        <p>
          Just pull page down to let the magic happen.<br />Note that pull-to-refresh feature is
          optimised for touch and native scrolling so it may not work on desktop browser.
        </p>
      </f7-block-footer>
    </f7-list>
  </f7-page>
</template>
<script>
import { f7Navbar, f7Page, f7List, f7ListItem, f7BlockFooter } from 'framework7-vue';

export default {
  components: {
    f7Navbar,
    f7Page,
    f7List,
    f7ListItem,
    f7BlockFooter,
  },
  data() {
    return {
      items: [
        {
          title: 'Yellow Submarine',
          author: 'Beatles',
          cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-1.jpg',
        },
        {
          title: "Don't Stop Me Now",
          author: 'Queen',
          cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-2.jpg',
        },
        {
          title: 'Billie Jean',
          author: 'Michael Jackson',
          cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-3.jpg',
        },
      ],
      songs: ['Yellow Submarine', "Don't Stop Me Now", 'Billie Jean', 'Californication'],
      authors: ['Beatles', 'Queen', 'Michael Jackson', 'Red Hot Chili Peppers'],
    };
  },
  methods: {
    loadMore(done) {
      const self = this;

      setTimeout(() => {
        const picURL = `https://cdn.framework7.io/placeholder/abstract-88x88-${
          Math.floor(Math.random() * 10) + 1
        }.jpg`;
        const song = self.songs[Math.floor(Math.random() * self.songs.length)];
        const author = self.authors[Math.floor(Math.random() * self.authors.length)];

        self.items.push({
          title: song,
          author,
          cover: picURL,
        });

        done();
      }, 1000);
    },
  },
};
</script>