Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vue] v-on可以绑定多个方法吗? #291

Open
haizhilin2013 opened this issue Jun 18, 2019 · 5 comments
Open

[vue] v-on可以绑定多个方法吗? #291

haizhilin2013 opened this issue Jun 18, 2019 · 5 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] v-on可以绑定多个方法吗?

@haizhilin2013 haizhilin2013 added the vue vue label Jun 18, 2019
@xn213
Copy link

xn213 commented Jun 18, 2019

可以 例如 input 的聚焦 失焦事件绑定各自的方法, 是不是可以这样理解

@censek
Copy link

censek commented Nov 22, 2019

<input type="text" :value="name" @input="onInput" @focus="onFocus" @blur="onBlur" />

@Sun11l
Copy link

Sun11l commented Dec 13, 2019

No description provided.

@lancelote-zpc
Copy link

  <input v-model="msg" type="text"
 v-on="{
input:a,
focus:b
}"/>

@Cai-zhiji
Copy link

v-on 指令可以绑定多个方法。可以使用多个事件处理函数来处理同一个事件。

<button v-on:click="handleClick, handleAnotherClick">Click me</button>
methods: {
  handleClick() {
    console.log('Clicked!');
  },
  handleAnotherClick() {
    console.log('Another Clicked!');
  }
}
···
在 Vue 实例的 methods 中定义了 handleClick 和 handleAnotherClick 两个方法,它们分别在按钮的点击事件中被绑定。

可以通过这种方式来实现多个方法对同一个事件进行响应,从而实现更灵活的事件处理。




Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

6 participants