I am having problem with this piece of code in vuetify:
<template>
..... {{ countf(options[1], options[2], options[3], options[4], options[5]) }} ......
</template>
<script lang="ts">
export default Vue.extend({
data () {
return {
count: 1,
str: ''
}
},
methods: {
countf(a: any, b: any, c: any, d: any, e: any) {
this.str = a.title;
if (this.str.indexOf("Lapel") > -1) {
this.count++;
}
return "Count = " + this.count;
}
}
})
</script>
I want to show Count = 2
in the webpage but whenever I navigate to this page, the page hangs. Can anyone help.
To further elabourate on my comment: the reason why your browser freezes is because the way your app is structured causes it to enter infinite recursion once any rendering is attempted:
countf()
method is invokedthis.count
and also returns a string that is not the same as beforeIf your logic is only supposed to run once, you can either invoke it in the
created
ormounted
lifecycle hook, and store the output in a string that is printed in the DOM. In that sense, you are ensuring that there is a one-way data flow.An example below illustrates a possible fix. It is not sure where
options
is coming from, so you might need to make some adjustments: