13 Star 48 Fork 17

小李 / vue-slideout

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Slideout

NPM Travis (.org) npm (scoped) npm bundle size (scoped) npm Coverage Status jsdelivr

一个 Vue3 的侧滑组件

依赖

  • Vue.js 3.x
  • Less

安装

Node 环境 (commonjs)

npm i @hyjiacan/vue-slideout@3

yarn add @hyjiacan/vue-slideout@3

你若想要兼容 Vue.js 2.x,那么使用版本 @hyjiacan/vue-slideout@2

可以通过以下方式获取最新代码:

git clone https://github.com/hyjiacan/vue-slideout.git

下载归档

浏览器环境 (umd)

与 node 环境一样, 此时会暴露一个全局 Slideout

使用最新版本


<script src="https://cdn.jsdelivr.net/npm/@hyjiacan/vue-slideout/dist/slideout.umd.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@hyjiacan/vue-slideout/dist/slideout.css"/>

使用指定版本


<script src="https://cdn.jsdelivr.net/npm/@hyjiacan/vue-slideout@<VERSION>/dist/slideout.umd.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@hyjiacan/vue-slideout@<VERSION>/dist/slideout.css"/>

unpkg 也可以使用: 替换 cdn.jsdelivr.netunpkg.com 可以通过替换 slideout.umd.min.jsslideout.umd.js 使用未被压缩的文件来

使用

全局引用 (推荐)

main.js

import Vue from 'vue'
import Slideout from '@hyjiacan/vue-slideout'
import '@hyjiacan/vue-slideout/dist/slideout.css'

// 引入 Slideout 组件,并设置组件默认值
Vue.use(Slideout, {
  // 在此处填写默认的属性值
})

组件内引用

Foobar.vue


<template>
  <slideout @closing="onClosing" v-model="visible" title="The title">
    <div>content</div>
  </slideout>
</template>
<script>
import Slideout from '@hyjiacan/vue-slideout'
import '@hyjiacan/vue-slideout/dist/slideout.css'

export default {
  name: 'Foobar',
  components: { Slideout },
  data () {
    return {
      visible: false
    }
  },
  methods: {
    onClosing (e) {
      // 阻止关闭,等待同步或异步的操作
      e.pause = true
      // 3秒后关闭slide
      setTimeout(() => {
        // 设置 close 为 true 以关闭,设置为 false 为什么也不做保持打开状态
        e.resume = true
      }, 3000)
    }
  }
}
</script>

马上到 CodePen

开发

yarn
# 启动服务器
yarn serve
# 构建仓库
yarn release

已知问题

溢出问题

情景:当指定了属性 offsetsize 的高度参数为 0 (自动适应高度), 并且 dock=left/right 时, 内容太高会导致溢出(无滚动条)。

解决方案:显式地给内容指定最大高度为确定的值(注意,不要超出可见区域),如:


<slide-out dock="left" :size="[300, 0]" offset="100px">
  <div style="max-height: 540px;overflow: auto">
    <!-- contents -->
  </div>
</slide-out>

其中的 max-height: 540px;overflow: auto 即可解决此问题。 max-height 可以通过 js 计算得到。

注意: 可能还需要考虑监听 window.resize 事件,以适应浏览器大小的变化。

The MIT License (MIT) Copyright © 2017 hyjiacan. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个 Vue2/3 的侧滑组件 展开 收起
JavaScript 等 4 种语言
MIT
取消

发行版 (3)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/hyjiacan/vue-slideout.git
git@gitee.com:hyjiacan/vue-slideout.git
hyjiacan
vue-slideout
vue-slideout
master

搜索帮助