javascript - 通过 Vuetify 组合框中的 @change 传递目标元素
问题描述
我需要通过updateTags
方法传递目标事件。这是下面的组合框:
当我调用该comboActive
方法时,我可以获得目标事件。
KeyboardEvent {isTrusted: true, key: "y", code: "KeyY", location: 0, ctrlKey: false, …}
请注意,comboActive
组合框中的方法不发送任何参数,但在该方法中comboActive(event)
我可以获取目标事件。
我希望能够在updateTags
方法中获取目标事件。如您所见,我尝试过使用$event
,但这不起作用
HTML:
<v-combobox multiple
v-model="select[i]"
append-icon
small-chips
deletable-chips
@keyup="comboActive"
@paste="updateTags(item,i)"
@change="updateTags(item,i,$event)">
</v-combobox>
脚本:
comboActive(event) {
console.log('active ', event)
event.target.parentElement.classList.add('saving')
},
updateTags(item, i, e) {
this.$nextTick(() => {
this.$nextTick(() => {
console.log('complete ', item, e)
})
})
},
当我添加时$event
,@change="updateTags(item,i,$event)"
我得到了项目数组。我需要组合框本身,以便我可以删除在comboActive
方法期间添加的类。
解决方案
我建议使用class binding
来处理这个问题,或者使用color
计算属性并通过添加一个名为的数据属性来有条件地更改它,saving
并在处理程序中更新它,@change
例如:
<v-combobox
:color="color"
...
@change="saving=true"
></v-combobox>
脚本
data () {
return {
saving:false,
select: ['Vuetify', 'Programming'],
items: [
'Programming',
'Design',
'Vue',
'Vuetify',
],
}
},
computed:{
color(){
return !this.saving? 'red':'grey'
}
},
推荐阅读
- linux - CodeIgniter 消息:实时服务器上的“找不到类”
- angular - 在延迟加载的模块中加载小型 Angular 模块
- reactjs - React Material UI + Formik FieldArray Autocomplete 控制值在删除时保持不变
- java - 骆驼端点没有被嘲笑
- angular - HTTP 成功响应后停止 RxJS HTTP 轮询
- excel - 正则表达式:VBA:使用条件评估表达式
- cobol - COBOL:将 PIC X 移动到 PIC S9.99 COMP-3
- r - 在 ggplot2 中添加图例
- javascript - Chart.JS:如何制作锐利的线条来平滑曲线
- python - Jupyter Notebook 不执行单元格/代码