1.0.2 • Published 2 months ago

@tanzhenxing/zx-read-more v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

zx-read-more 阅读更多组件

一个用于内容收起/展开的通用组件,支持 H5、小程序、APP,基于 Vue3 setup 语法,兼容多端。

基本用法

<zx-read-more :showHeight="80">
  <text>很长的内容...</text>
</zx-read-more>

属性说明

属性名说明类型默认值
showHeight内容超出此高度才显示展开按钮String/Number400
toggle展开后是否显示收起按钮Booleanfalse
closeText关闭时的提示文字String展开阅读全文
openText展开时的提示文字String收起
color提示文字颜色String#2979ff
fontSize提示文字大小(px)String/Number14
shadowStyle阴影样式对象Object见下方
textIndent段落首行缩进String2em
name事件回调参数String/Number''

shadowStyle 默认值

{
  backgroundImage: 'linear-gradient(-180deg, rgba(255,255,255,0) 0%, #fff 80%)',
  paddingTop: '100px',
  marginTop: '-100px',
}

事件说明

事件名说明回调参数
open内容被展开时触发name
close内容被收起时触发name

插槽

名称说明
默认展示的内容
toggle自定义展开/收起区域

进阶用法

自定义展开/收起文字

<zx-read-more closeText="查看更多" openText="收起内容">
  <text>内容...</text>
</zx-read-more>

自定义插槽

<zx-read-more>
  <text>内容...</text>
  <template #toggle>
    <view style="color: #4caf50; font-weight: bold; text-align: center;">点我展开/收起</view>
  </template>
</zx-read-more>

事件监听

<zx-read-more @open="onOpen" @close="onClose">
  <text>内容...</text>
</zx-read-more>

注意事项

  • 组件已兼容 H5、各类小程序、APP(nvue),无需关心平台差异。
  • 内容高度计算基于 uniapp 官方 API,无浏览器特有 DOM。
  • 如需自定义样式,可通过外部 class 或 style 覆盖。

完整示例

详见 src/pages/components/read-more/index.vue