I have created a data array in Vue.js to help me build details of a list of counties in the UK. As a final step, I would like to create links between related county pages based on the data I have included in the array.
I would like to loop through the main county object and compare the items in closeby to the county name.
Currently, my data looks something like so:
createApp({
data() {
return {
counties: [
{
county: 'Bedfordshire',
link: 'example.com/link',
districts: [
{ authority: "Bedford" },
{ authority: "Luton" }
],
cities: false,
coastal: false,
flag: true,
closeby: [
{ county: 'Cambridgeshire' },
{ county: 'Hertfordshire' },
{ county: 'Buckinghamshire' },
{ county: "Northamptonshire" }
]
},
...
],
}
}
}).mount('#app')
The array obviously goes on like this for each county, but I have trimmed it for ease of reading
and to spit out the section related to closeby I have:
<span v-for="(neighbour, index) in county.closeby">
<span v-if="index !== 0 && index !== county.closeby.length - 1">, </span>
<span v-if="index == county.closeby.length - 1 && county.closeby.length > 1"> and </span>
{{ neighbour.county }}
</span>
This outputs: Cambridgeshire, Hertfordshire, Buckinghamshire and Northamptonshire
What I would like to do is include the link of each county alongside the county's relevant county name eg:
Cambridgeshire (example.com/link1), Hertfordshire (example.com/link2), Buckinghamshire (example.com/link3) and Northamptonshire (example.com/link4)
How do I compare the items in closeby to the link for each county in counties to enable them to be displayed? Bearing in mind the number of items in closeby will vary