Accessing $refs Array Inside A Vue JS Instance Watch Object
I am building a Vue JS SPA, and have a Vuetify data-table inside of the v-app. I am trying to set a variable inside the watch object for the filteredItems computed property inside
Solution 1:
The best way is to add watcher on the mounted. Try the following code.
mounted(){
this.$watch(
() => {
return this.$refs.prospectsTable.filteredItems
},
(val) => {
console.log(val)
alert('App $watch $refs.counter.i: ' + val)
}
)
}
Codepen - https://codesandbox.io/s/j7wjjypnxw
Solution 2:
It might be sat in $root because of where the component it is declared.
If $refs.prospectsTable
is not working then try $root.$refs.prospectsTable
.
Perhaps also this should be keys in a watcher as a string as so:
watch: {
'$refs.prospectsTable.filteredItems': function (value) {
console.log(value);
}
}
Post a Comment for "Accessing $refs Array Inside A Vue JS Instance Watch Object"