@7anshuai/vue-auto-sizer 中文文档教程

发布于 3年前 浏览 26 项目主页 更新于 3年前

vue-auto-sizer

自动调整单个子项宽高的vue组件。

注意:vue-auto-sizer 是 react-virtualized-auto-sizer< 的 vue 克隆/a>

Prop Types

PropertyTypeRequired?Description
defaultHeightNumberHeight passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate height after mounting.
defaultWidthNumberWidth passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate width after mounting.
disableHeightBooleanFixed height; if specified, the child's height property will not be managed
disableWidthBooleanFixed width; if specified, the child's width property will not be managed
nonceStringNonce of the inlined stylesheets for Content Security Policy
onResizeFunctionCallback to be invoked on-resize; it is passed the following named parameters: ({ height: number, width: number }).

Examples

一些 vue 组件需要显式尺寸,但有时您只希望组件增长以填充所有可用空间。 AutoSizer 组件在这种情况下很有用。

关于将 AutoSizer 与 flexbox 容器一起使用的注意事项。 Flex 容器不会阻止它们的子容器增长,AutoSizer 会贪婪地增长以填充尽可能多的空间。 将两者结合起来可能会导致循环。 解决此问题的简单方法是将 AutoSizer 嵌套在 block 元素(如

)中,而不是将其作为flex 容器的直接子容器。 在此处阅读有关AutoSizer 常见问题的更多信息。

<template>
  <div id="app">
    <h1>
      <img alt="Vue logo" src="./assets/logo.png">
    </h1>

    <p>
      vue-auto-sizer is a vue clone of <a href="https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md">React virtualized auto sizer</a>
    </p>

    <div class="auto-sizer-wrapper">
      <auto-sizer v-slot="{ sizer: { height, width} }">
        <div :style="{ height: height + 'px', width: width + 'px' }">
          Auto sized content...
        </div>
      </auto-sizer>
    </div>
  </div>
</template>

<script>
import AutoSizer from 'vue-auto-sizer'

export default {
  name: 'App',
  components: {
    AutoSizer
  },
  methods: {
    onResize ({ height, width }) {
      console.log(height, width)
    }
  }
}
</script>

<style>
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.auto-sizer-wrapper {
  flex: 1 1 auto;
}
</style>

Development

yarn install

Compiles and hot-reloads for development

yarn serve

Compiles and minifies for production

yarn build:lib

Run your unit tests

yarn test:unit

Lints and fixes files

yarn lint

Customize configuration

请参阅配置参考

vue-auto-sizer

Vue component that automatically adjusts the width and height of a single child.

Note: vue-auto-sizer is a vue clone of react-virtualized-auto-sizer

Prop Types

PropertyTypeRequired?Description
defaultHeightNumberHeight passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate height after mounting.
defaultWidthNumberWidth passed to child for initial render; useful for server-side rendering. This value will be overridden with an accurate width after mounting.
disableHeightBooleanFixed height; if specified, the child's height property will not be managed
disableWidthBooleanFixed width; if specified, the child's width property will not be managed
nonceStringNonce of the inlined stylesheets for Content Security Policy
onResizeFunctionCallback to be invoked on-resize; it is passed the following named parameters: ({ height: number, width: number }).

Examples

Some vue components require explicit dimensions but sometimes you just want a component to just grow to fill all of the available space. The AutoSizer component can be useful in this case.

One word of caution about using AutoSizer with flexbox containers. Flex containers don't prevent their children from growing and AutoSizer greedily grows to fill as much space as possible. Combining the two can cause a loop. The simple way to fix this is to nest AutoSizer inside of a block element (like a <div>) rather than putting it as a direct child of the flex container. Read more about common AutoSizer questions here.

<template>
  <div id="app">
    <h1>
      <img alt="Vue logo" src="./assets/logo.png">
    </h1>

    <p>
      vue-auto-sizer is a vue clone of <a href="https://github.com/bvaughn/react-virtualized/blob/master/docs/AutoSizer.md">React virtualized auto sizer</a>
    </p>

    <div class="auto-sizer-wrapper">
      <auto-sizer v-slot="{ sizer: { height, width} }">
        <div :style="{ height: height + 'px', width: width + 'px' }">
          Auto sized content...
        </div>
      </auto-sizer>
    </div>
  </div>
</template>

<script>
import AutoSizer from 'vue-auto-sizer'

export default {
  name: 'App',
  components: {
    AutoSizer
  },
  methods: {
    onResize ({ height, width }) {
      console.log(height, width)
    }
  }
}
</script>

<style>
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.auto-sizer-wrapper {
  flex: 1 1 auto;
}
</style>

Development

yarn install

Compiles and hot-reloads for development

yarn serve

Compiles and minifies for production

yarn build:lib

Run your unit tests

yarn test:unit

Lints and fixes files

yarn lint

Customize configuration

See Configuration Reference.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文