我正在尝试使用Filepond上传一些图像。上载正常。我还想查看上传图像的预览。我曾尝试使用该插件,但显然没有任何变化。
{% block style %}
<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.min.css" rel="stylesheet">
{% endblock %}
以下是我的脚本
{% block scripts %}
</script>
<!-- FILE POND STUFF -->
<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>
FilePond.parse(document.body);
</script>
{% endblock %}
这是我的JS文件
$('#file_upload').change(function() {
const inputElement = document.querySelector('input[type="file"]');
FilePond.registerPlugin(FilePondPluginImagePreview);
const pond = FilePond.create( inputElement, {
allowMultiple: true,
allowFileEncode: true,
});
}
我的HTML代码
<input type="file" name='file' class='filepond' multiple id='file_upload'/>
我无法确定是否还有其他步骤。
答案 0 :(得分:0)
如果还不算太晚,这里是一个有效的演示https://jsfiddle.net/yza54qp0/1/
const inputElement = document.querySelector('#file_upload');
FilePond.registerPlugin(FilePondPluginImagePreview);
const pond = FilePond.create( inputElement, {
allowMultiple: true,
allowFileEncode: true,
});
<link href="https://unpkg.com/filepond-plugin-image-preview@4.2.1/dist/filepond-plugin-image-preview.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/filepond@4.4.10/dist/filepond.css" rel="stylesheet"/>
<script src="https://unpkg.com/filepond-plugin-image-preview@4.2.1/dist/filepond-plugin-image-preview.js"></script>
<script src="https://unpkg.com/filepond@4.4.10/dist/filepond.js"></script>
<input type="file" name='file' class='filepond' multiple id='file_upload'/>
<script>
FilePond.parse(document.body);
</script>