Although this issue has been addressed before in a discussion about the "You may have an infinite update loop in a component render function" warning in Vue component, the solution provided did not resolve my problem.
I am seeking assistance to understand what might be causing the issue in my case.
<template>
<div>
<template v-for="listing in sortedListings">
<listing
:key="listing.uuid"
:listing="listing"
:highlight-color="listing.highlight ? getHighlightColor() : null"
/>
</template>
</div>
</template>
<script>
import Listing from '@/components/Listing'
export default {
components: {
Listing,
},
data: function () {
return {
highlightColors: this.getHighlightColors(),
listings: [
{
uuid: '658f325f-33c8-455b-98f6-27eb4eaa16a0',
title: 'Cursus Nullam Amet Tortor',
location: 'Remote',
url: 'http://example.net/birds',
hours_week: 20,
tags: ['django', 'python', 'flask'],
logo: 'https://logo.clearbit.com/apple.com',
company_name: 'Apple',
show_logo: 1,
highlight: 0,
stick_top: 0,
},
// additional listing items...
],
}
},
computed: {
sortedListings: function () {
return [...this.listings].sort(function (a, b) {
return b.stick_top - a.stick_top
})
},
},
methods: {
getListings: async function () {},
getHighlightColors: function () {
return this.shuffleArray([
'#E3F2FD',
'#E8EAF6',
'#FFEBEE',
'#E0F2F1',
'#E8F5E9',
'#FFF3E0',
'#FFFDE7',
])
},
getHighlightColor: function () {
if (this.highlightColors.length === 0) {
this.highlightColors = this.getHighlightColors()
}
return this.highlightColors.shift()
},
},
mounted: function () {
this.getListings()
},
}
</script>
In the computed property sortedListings
, I have already implemented [...this.listings]
.