在我反应过来组件我试图触发在下面的函数创建超链接点击:如何触发超级链接点击什 - 反应成分
getUsers(e){
e.preventDefault();
const { userIds } = this.props;
BatchRoleActions.getAllRoleUsers(userIds)
.then((users) => {
const link = document.createElement('a');
link.setAttribute('id', 'csvLink');
link.setAttribute('download', 'roles.csv');
link.setAttribute('href', users);
document.getElementById('csvLink').onClick();
});
}
当运行该功能时,我得到了以下错误: 未捕获(承诺中)TypeError:无法读取属性'onClick'为空
如何触发点击开始我的下载?
BatchRoleActions.getAllRoleUsers(userIds)返回一个数组,其中包含用于导出到csv文件的数据。 encodeURI(data:text/csv;charset=utf-8,\uFEFF${data}
);
我试图找到一个解决方案:ReactJs - How to complete onClick before download - href
你拼写的下载'OnClick'错大写的O,但我们需要更多的信息来帮助你 –
你还没有它插入到DOM。不管怎样,不要将本机DOM方法与React混合使用... – Li357
最好的方法是什么? – user1526912