docs(ImagePreview): fix warning

This commit is contained in:
chenjiahan 2021-09-07 11:19:47 +08:00
parent a9b4f88860
commit 6e5f215140
2 changed files with 29 additions and 21 deletions

View File

@ -1,10 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanImagePreview, { ImagePreview, ImagePreviewOptions } from '..'; import { ImagePreview, ImagePreviewOptions } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const VanImagePreview = ImagePreview.Component;
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
closed: '关闭', closed: '关闭',
@ -73,33 +75,37 @@ const showImagePreview = (options: Partial<ImagePreviewOptions> = {}) => {
<template> <template>
<demo-block card :title="t('basicUsage')"> <demo-block card :title="t('basicUsage')">
<van-cell is-link @click="showImagePreview()"> <van-cell is-link :value="t('showImages')" @click="showImagePreview()" />
{{ t('showImages') }}
</van-cell>
</demo-block> </demo-block>
<demo-block card :title="t('customConfig')"> <demo-block card :title="t('customConfig')">
<van-cell is-link @click="showImagePreview({ startPosition: 1 })"> <van-cell
{{ t('startPosition') }} is-link
</van-cell> :value="t('startPosition')"
<van-cell is-link @click="showImagePreview({ closeable: true })"> @click="showImagePreview({ startPosition: 1 })"
{{ t('showClose') }} />
</van-cell> <van-cell
<van-cell is-link @click="showImagePreview({ onClose })"> is-link
{{ t('closeEvent') }} :value="t('showClose')"
</van-cell> @click="showImagePreview({ closeable: true })"
/>
<van-cell
is-link
:value="t('closeEvent')"
@click="showImagePreview({ onClose })"
/>
</demo-block> </demo-block>
<demo-block card :title="t('beforeClose')"> <demo-block card :title="t('beforeClose')">
<van-cell is-link @click="showImagePreview({ beforeClose })"> <van-cell
{{ t('beforeClose') }} is-link
</van-cell> :value="t('beforeClose')"
@click="showImagePreview({ beforeClose })"
/>
</demo-block> </demo-block>
<demo-block card :title="t('componentCall')"> <demo-block card :title="t('componentCall')">
<van-cell is-link @click="showComponentCall"> <van-cell is-link :value="t('componentCall')" @click="showComponentCall" />
{{ t('componentCall') }}
</van-cell>
<van-image-preview v-model:show="show" :images="images" @change="onChange"> <van-image-preview v-model:show="show" :images="images" @change="onChange">
<template #index>{{ t('index', index) }}</template> <template #index>{{ t('index', index) }}</template>
</van-image-preview> </van-image-preview>

View File

@ -51,7 +51,7 @@ function initInstance() {
} }
const ImagePreview = ( const ImagePreview = (
images: string[] | ImagePreviewOptions, options: string[] | ImagePreviewOptions,
startPosition = 0 startPosition = 0
) => { ) => {
/* istanbul ignore if */ /* istanbul ignore if */
@ -63,7 +63,9 @@ const ImagePreview = (
initInstance(); initInstance();
} }
const options = Array.isArray(images) ? { images, startPosition } : images; options = Array.isArray(options)
? { images: options, startPosition }
: options;
instance.open(extend({}, defaultConfig, options)); instance.open(extend({}, defaultConfig, options));