因为火狐的兼容性问题,在想要点击a标签下载文件,同时对它添加点击事件记录下载次数时,会出现只有href属性生效,onclick内的函数无效的现象。在网上找了很多方法都无法解决,无法同时使用href和onclick属性。
<a href="url" @onclick="count(id)">下载</a>
count(id) {
updateCount(id).then(res => { ...}) // 远程方法
}
解决方法:
只使用onclick事件。
1、如果用window.open(url)来实现href的效果会导致页面刷新闪烁,体验不好。
2、正确方法:使用location.href = url 来实现href的功能,不会刷新闪烁。
<a @onclick="count(id, url)">下载</a>
count (id, url) {
location.href = url
updateCount(id).then(res => { ...})
}