首页 > 解决方案 > 我无法在文件池上进行图像预览

问题描述

我已经尽一切努力让它工作,但它还没有工作

我从 cdn 加载,就像在预览文档中一样

<!-- add to document <head> -->
<link href="https://unpkg.com/filepond/dist/filepond.css" 
rel="stylesheet">
<link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond- 
plugin-image-preview.css" rel="stylesheet">

<!-- add before </body> -->
<script src="https://unpkg.com/filepond-plugin-image- 
preview/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>

为了增强到文件池元素,我有

<script>
const inputElement = document.querySelector('input[type="file"]');
const pond = FilePond.create( inputElement );
</script>

最后

<input type="file">

它只是显示为一个文件,而不是图像预览。我错过了什么?

标签: filepond

解决方案


插件尚未在 FilePond 中注册。

这应该有效:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FilePond Plugin Image Preview Demo</title>
    <link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
    <link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.css" rel="stylesheet">
</head>
<body>

    <input type="file"/>

    <script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.js"></script>
    <script src="https://unpkg.com/filepond/dist/filepond.js"></script>

    <script>
    // Register the plugin with FilePond
    FilePond.registerPlugin(FilePondPluginImagePreview);

    // Get a reference to the file input element
    const inputElement = document.querySelector('input[type="file"]');

    // Create the FilePond instance
    const pond = FilePond.create(inputElement);
    </script>

</body>
</html>

现场演示:https ://pqina.github.io/filepond-plugin-image-preview/

我正在查看文档,我发现这是多么令人困惑,一旦我有时间就会改进它们。


推荐阅读