页面 Vue 组件

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

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

页面组件

包含以下组件:

页面属性

属性类型默认描述
<f7-page> 属性
name字符串页面名称
消息内容布尔值如果您在页面内部使用消息component
页面内容布尔值true当启用时,它会自动添加page-content元素。当您需要使用几个页面内容元素用于选项卡时,禁用它很有用
tabs布尔值如果您将页面用作标签页包装器
登录屏幕布尔值如果您在页面内部使用登录屏幕以添加所需的额外样式
无滑动返回布尔值禁用当前页面的滑动返回功能(仅影响 iOS 主题)
带子导航栏布尔值如果您在页面内部有子导航栏,请启用
无导航栏布尔值如果您使用常见的导航栏布局,并且需要隐藏常见的导航栏(或使用另一个)为此页面(仅影响 iOS 主题)
无工具栏布尔值如果您使用常见的工具栏/选项卡栏布局,并且需要隐藏工具栏(或使用另一个)为此页面
滚动时隐藏条目布尔值在页面滚动时隐藏导航栏和工具栏
滚动时隐藏导航栏布尔值在页面滚动时隐藏导航栏
滚动时隐藏工具栏布尔值在页面滚动时隐藏工具栏
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布尔值如果您将页面内容用作选项卡,请启用
tab-active布尔值如果当前选项卡处于活动状态,请启用
ptr
ptr-distance
ptr-preloader
ptr-bottom
ptr-mousewheel
infinite
infinite-top
infinite-distance
infinite-preloader
滚动时隐藏条目
滚动时隐藏导航栏
滚动时隐藏工具栏
消息内容
登录屏幕
<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>
无噪 Logo
无噪文档
中文文档 · 复刻官网
查看所有 ↗