温馨提示×

vue中如何模拟点击事件

vue
养鱼的猫咪
3848
2021-05-13 11:42:25
栏目: 编程语言

在vue中模拟点击事件的方法:1.新建vue.js项目;2.添加按钮,设置ref属性;3.添加@click属性绑定事件;4.使用this方法触发事件;

vue中如何模拟点击事件

具体步骤如下:

1.首先,在vue-cli中创建一个vue.js项目;

vue create project-name

2.vue.js项目创建好后,在项目中添加一个按钮,并设置ref属性;

<el-button size="small" type="primary" ref="import">导入</el-button>

3.按钮添加好后,在按钮中添加一个@click属性,用于绑定事件;

<el-button size="small" type="primary" ref="import" @click="searchData()">导入</el-button>

4.最后,事件绑定好后,使用this方法即可触发点击事件;

this.$refs.import.$el.click()

0