I want to display the length of an array in my vue component. The array is nested in a vue plugin.
Everytime I start an API Call
I 'push' a new element in this array found here: this.$apiCall.apiCallCache
Is this possible to watch for changes on this array? Am I doing something wrong in the example below?
I only get 0
the hole time. But if I click on the button and trigger logApiCache()
it will console.log the right length of the array while the computed function still shows 0 in the span element / tooltip.
<template>
<v-footer
app
tile
>
<span>Queue: {{ footerClockTooltip() }}</span>
<app-footer-button
:name="'Clock'"
:tooltip="footerClockTooltip()"
:icon="$icons.mdiClockOutline"
@click="logApiCache"
/>
</v-footer>
</template>
<script>
export default {
name: 'Footer',
computed: {
/*
footerClockTooltip() {
return this.$apiCall.apiCallCache.length
}
*/
},
methods: {
logApiCache() {
this.$forceUpdate()
console.error(`logApiCache: ${this.$apiCall.apiCallCache.length}`, this.$apiCall.apiCallCache)
},
footerClockTooltip() {
console.error('New Queue:', this.$apiCall.apiCallCache.length)
return this.$apiCall.apiCallCache.length
}
}
}
</script>
Edit:
Here is my Vue plugin:
import Vue from 'vue'
const ApiClass = require('../classes/ApiClass')
const api = new ApiClass()
// Export Vue Plugin
const ApiCalls = {
install(Vue) {
Object.defineProperties(Vue.prototype, {
$apiCall: {
get() {
return api
}
}
})
}
}
Vue.use(ApiCalls)
Thanks for the help. :)
"nuxt": "2.12.2"
. The importan part for my array I want to watch is inaddCall
>this.apiCallCache.push({ ... })
– borsTiHDApiClass
. Then I bind this instance to my Vue object, so I can access it withthis.$apiCall
. Now, if I start a request/api call in an seperate component, I just callthis.$smcApiCall.addCall(request, callback)
. TheaddCall
function then pushs a new object into an array of the class property. – borsTiHD