1
0
mirror of https://gitee.com/vant-contrib/vant.git synced 2025-04-06 03:57:59 +08:00

[improvement] ImagePreview: add showIndicators prop ()

This commit is contained in:
neverland 2018-10-29 17:46:12 +08:00 committed by GitHub
parent 2e3ecf6402
commit edaad55e30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 7 deletions

@ -10,7 +10,7 @@
<swipe
ref="swipe"
:initial-swipe="startPosition"
:show-indicators="false"
:show-indicators="showIndicators"
@change="onChange"
>
<swipe-item v-for="(item, index) in images" :key="index">
@ -50,6 +50,7 @@ export default create({
},
props: {
showIndicators: Boolean,
images: {
type: Array,
default: () => []

@ -52,4 +52,5 @@ setTimeout(() => {
| images | Images URL list | `Array` | `[]` |
| startPosition | Start position | `Number` | `0` |
| showIndex | Whether to show index | `Boolean` | `true` |
| showIndicators | Whether to show indicators | `Boolean` | `false` |
| onClose | Close callback | `Function` | - |

@ -4,6 +4,14 @@ import { isServer } from '../utils';
let instance;
const defaultConfig = {
value: true,
images: [],
showIndex: true,
showIndicators: false,
startPosition: 0
};
const initInstance = () => {
instance = new (Vue.extend(VueImagePreview))({
el: document.createElement('div')
@ -21,17 +29,18 @@ const ImagePreview = (images, startPosition) => {
initInstance();
}
const config = Array.isArray(images) ? { images, startPosition } : images;
const options = Array.isArray(images) ? { images, startPosition } : images;
Object.assign(instance, {
...defaultConfig,
...options
});
instance.value = true;
instance.images = config.images;
instance.showIndex = config.showIndex || true;
instance.startPosition = config.startPosition || 0;
instance.$on('input', show => {
instance.value = show;
if (!show) {
instance.$off('input');
config.onClose && config.onClose();
options.onClose && options.onClose();
}
});

@ -60,4 +60,5 @@ setTimeout(() => {
| images | 需要预览的图片 URL 数组 | `Array` | `[]` | 1.1.16 |
| startPosition | 图片预览起始位置索引 | `Number` | `0` | 1.1.16 |
| showIndex | 是否显示页码 | `Boolean` | `true` | 1.3.4 |
| showIndicators | 是否显示轮播指示器 | `Boolean` | `false` | 1.3.10 |
| onClose | 关闭时的回调函数 | `Function` | - | 1.1.16 |

@ -4,6 +4,7 @@ export type ImagePreviewOptions = string[] | {
images: string[];
startPosition?: number;
showIndex?: boolean;
showIndicators?: boolean;
onClose?: () => any;
};