【问题标题】:Error while trying to use nativescript-photoviewer with vue尝试将 nativescript-photoviewer 与 vue 一起使用时出错
【发布时间】:2021-04-02 02:47:12
【问题描述】:

我正在使用 nativescript-vue 开发一个应用程序,我需要显示一些外部图像。

我正在尝试使用 nativescript-photoviewer 插件。

这是我的代码:

<template>
...
<Image :src="image_path" @tap="onImageTap" />
...
</template>

<script>
// Include the module
import { PhotoViewer, PhotoViewerOptions, PaletteType, NYTPhotoItem } from "nativescript-photoviewer";
...
methods: {
 onImageTap: function() {
            let image1 =
                "https://pat-book.es/storage/user_images/allergies/3qwTKMNU2tRqHhJtFRce5S3fNgel9twafrFl9FWj.jpeg";
            let image2 =
                "https://pat-book.es/storage/user_images/allergies/4MtvyhpyzHIdj993pEj3MoubmRJQWAhGdhotaT6h.jpeg";

            let images = [image1, image2];

            let photoViewer = new PhotoViewer();

            photoViewer.showGallery(images);
}
</script>

这些图像是动态的。

我不使用选项,只要它们是可选的。

这是我得到的错误:

JS: [Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'startIndex' of undefined"
System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onTouch failed
System.err: TypeError: Cannot read property 'startIndex' of undefined
System.err:
System.err: StackTrace:
System.err: PhotoViewer.showGallery(file:///app\photoviewer.android.ts:21:41)
System.err:     at onImageTap(file:///app\pages\allergies\AllergiesDetailsPage.vue:173:0)
...

这是错误上升的插件源代码:

    public showGallery(imagesArray: Array<string>, options?: PhotoViewerOptions) {
        var photosArray = new java.util.ArrayList();
    
        imagesArray.forEach((imgUrl: string) => {
            photosArray.add(imgUrl);
        });
    
        let startIndex: number = options.startIndex || 0; // Line 21
...

有人设法用 vue 运行这个插件吗?提供的唯一示例是 angular 和 typescript。

【问题讨论】:

    标签: vue.js nativescript


    【解决方案1】:

    尝试将空对象作为第二个参数传递给 showGallery 方法,看起来它并不是真正的可选参数。

    photoViewer.showGallery(images, {});
    

    【讨论】:

      猜你喜欢
      • 2021-08-04
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 2017-09-27
      • 1970-01-01
      相关资源
      最近更新 更多