使用vue开发时,通过ref通过“this.refs.[name].$el.click()”触发按钮时提示“File chooser dialog can only be shown with a user activation.”,按钮不能触发,网上解决办法是“dispatchEvent(new MouseEvent('click'))”代替“$el.click()”,在我所在的场景不生效,所以就在要出发按钮组件上加了一个id,按钮可以正常触发了
<template>
<el-button ref="btn" id="btn" >测试</el-button>
</template>
<script>
export default{
methods:{
clickBtn(){
this.$refs.btn.$el.click()
}
</script>