Vue.js Vuetify v-treeview如何获取最后选定的元素?
Vuetify v-treeview如何获取“获取最后一个选定元素”Vue.js Vuetify v-treeview如何获取最后选定的元素?,vue.js,vuetify.js,Vue.js,Vuetify.js,Vuetify v-treeview如何获取“获取最后一个选定元素” <v-treeview v-model="treeModel" :items="items" selectable="selectable" > ## option 2 - use watch this option, at the moment, is preferred. It uses a watch to trigger the action when the
<v-treeview
v-model="treeModel"
:items="items"
selectable="selectable"
>
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
通过treeModel,我已经选择了所有项目,但是如何仅通过在
v-model中提供最后一个项目的id来获得最后一个选中的项目(单击)?
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
修改的示例来自
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
选项1-使用v-on/@on更新:活动
**目前不适用于VUETIFY v2**
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
newvue({
el:“#应用程序”,
vuetify:新的vuetify(),
数据:()=>({
选择:[],
项目:[
{
id:1,
名称:“应用程序:”,
儿童:[
{id:2,名称:'Calendar:app'},
{id:3,名称:'Chrome:app'},
{id:4,名称:'Webstorm:app'},
],
},
{
id:5,
名称:“文档:”,
儿童:[
{id:6,名称:'Calendar.doc'},
{id:7,名称:'Chrome.doc'},
{id:8,名称:'Webstorm.doc'},
],
},
],
}),
方法:{
更新(选择){
console.log(选择)
}
}
})
问题是,如果使用vuetify v2.0.0-v2.0.5,该操作实际上并不适用于选择,而是适用于可激活的
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
如果要查找最后选定的项目,可以在此处使用数组差异
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
观察:{
选择(新值、旧值){
var arrDiff=myarrdifpredency.added(newValue,oldValue)
此.onUpdate(arrDiff)
}
},
仅在v型中提供最后一项的id
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
修改的示例来自
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
选项1-使用v-on/@on更新:活动
**目前不适用于VUETIFY v2**
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
newvue({
el:“#应用程序”,
vuetify:新的vuetify(),
数据:()=>({
选择:[],
项目:[
{
id:1,
名称:“应用程序:”,
儿童:[
{id:2,名称:'Calendar:app'},
{id:3,名称:'Chrome:app'},
{id:4,名称:'Webstorm:app'},
],
},
{
id:5,
名称:“文档:”,
儿童:[
{id:6,名称:'Calendar.doc'},
{id:7,名称:'Chrome.doc'},
{id:8,名称:'Webstorm.doc'},
],
},
],
}),
方法:{
更新(选择){
console.log(选择)
}
}
})
问题是,如果使用vuetify v2.0.0-v2.0.5,该操作实际上并不适用于选择,而是适用于可激活的
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
如果要查找最后选定的项目,可以在此处使用数组差异
## option 2 - use watch
this option, at the moment, is preferred. It uses a watch to trigger the action when the `v-model` changes
```html
<div id="app">
<v-app id="inspire">
<v-treeview
v-model="selection"
:items="items"
selectable
></v-treeview>
</v-app>
</div>
观察:{
选择(新值、旧值){
var arrDiff=myarrdifpredency.added(newValue,oldValue)
此.onUpdate(arrDiff)
}
},
非常感谢@Daniel的回答,每次活动物品更改后,我都需要获得选定的物品。可以使用v-on:update:active=“update”和方法:{update:function(data){this.activeItem=data;}}完成。如果你更新你的答案,我会接受。更新答案。我不确定您使用的vuetify是哪个版本,但如果是v2.0,您可能需要使用手表而不是动作,或者使用可激活而不是选择(除非这是您首先想要的)。非常感谢@Daniel的回答,在每次活动项目更改后,我都需要获得选定的项目。可以使用v-on:update:active=“update”和方法:{update:function(data){this.activeItem=data;}}完成。如果你更新你的答案,我会接受。更新答案。我不确定您使用的vuetify版本是什么,但如果是v2.0,您可能需要使用手表而不是action,或者使用Activable而不是selection(除非这是您首先想要的)