Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 react useRef 钩子打开文件对话框。
当浏览器执行 fileInputRef.current.click() 代码片段时,我在控制台中遇到错误
错误:文件选择器对话框只能在用户激活时显示
这很好用:
const inputFileRef = useRef(); ... const handleBtnClick = () => { inputFileRef.current.click(); } ... <form> <input type="file" ref={inputFileRef} /> <button onClick={handleBtnClick}>Select file</button> </form>