简体   繁体   English

如何将“this”以及 v-model 从输入传递给处理程序

[英]How to pass "this" as well as v-model from input to handler

How do I pass the this object (referring to the input element vs. whole component) to a handler function in Vue?如何将this对象(指输入元素与整个组件)传递给 Vue 中的处理程序函数?

<input
  type="number"
  min="0"
  max="8000000"
  step="100000"
  v-model="minPriceInput"
  @change="setPriceRange(minPriceInput, maxPriceInput)"
/>

methods:方法:

setPriceRange(min, max) {
  this.blur(); // or whatever else I might do with the input
  state.commit("setPriceRange", [min, max]);
}

You can pass the event with the parameters as follows setPriceRange($event, minPriceInput, maxPriceInput);您可以使用如下参数传递事件setPriceRange($event, minPriceInput, maxPriceInput); and use it through event.target .并通过event.target使用它。 Another thing you can do is giving it an id and calling it normally using document.getElementById("minPrice") ...你可以做的另一件事是给它一个 id 并使用document.getElementById("minPrice")正常调用它......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM