Advertisement

小程序中隐藏输入用于文件上传(react+fetch)

阅读量:

jsx

复制代码
     <div onClick={handleUpload()} > </div>
    
    
      
    
复制代码
    handleUpload() {
    	tools.uploadFile({}).then((res) => {
       //实现自己的逻辑
      })
    }
    
    
      
      
      
      
      
    

tools文件

原生方法概述

复制代码
    uploadFile() {
    		//防止浏览器选择了文件但是不上传出现重复browserFile
    		let oldbrowserFile = document.querySelector("#browserFile")
    		if (oldbrowserFile) {
    				oldbrowserFile.remove()
    		}
    		const input = document.createElement("input");
    		input.setAttribute("type", "file");
    		input.setAttribute("name", "file");

全部评论 (0)

还没有任何评论哟~