I have been stuck on this for a while, have been on Google, Stack Overflow, read over 100 posts however no luck finding the explanation on what is happening.
I'm new on VUE and still learning but this thing baffles me.
I've got a list of people data objects where v-for code is initiated and rows are represented within the table depending on the data object.
<tr v-for="person in people" :key="person.id">
<td>
<router-link
:to="{name: 'person-edit', params: { id: person.id }}"
>{{person | fullName}}</router-link>
</td>
<!-- Shows No as a result-->
<td>{{(person | palindrome) ? 'Yes' : 'No'}}</td>
<!-- Shows No as a result-->
<td v-if="person | palindrome">Yes</td>
<td v-else>No</td>
<!-- Shows true as a result-->
<td>{{person | palindrome}}</td>
<td>{{person.authorised ? 'Yes' : 'No'}}</td>
<td>{{person.enabled ? 'Yes' : 'No'}}</td>
<td>{{person.colours | colourNames}}</td>
</tr>
First and second code examples also prints on a client console this error:
[Vue warn]: Property or method "palindrome" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
Since {{person | palindrome}} returns true this proves that palindrome function is functioning, however, I'm unable to render Yes or No within HTML code part.
<script lang="ts">
import Vue from 'vue';
import {getPeople} from '../api/people-api';
export default Vue.extend({
async mounted() {
this.people = await getPeople();
},
data() {
const people: IPerson[] = [];
return {
people,
};
},
filters: {
colourNames: (colours: IColour[]): string => {
const coloursString: string[] = [];
colours.forEach((colour) => {
coloursString.push(colour.name);
});
return coloursString.sort().join();
},
fullName: (person: IPerson): string => {
return `${person.firstName} ${person.lastName}`;
},
palindrome: (person: IPerson): boolean => {
const fullName = `${person.firstName} ${person.lastName}`;
// TODO: Step 5
//
// Implement the palindrome computed field.
// True should be returned When the FullName is spelt the same
// forwards as it is backwards. The match should ignore any
// spaces and should also be case insensitive.
//
// Example: "Bo Bob" is a palindrome.
const nameLowerCase = fullName.toLowerCase().split(' ').join('');
const nameReversed = nameLowerCase.split('').reverse().join('');
return nameLowerCase === nameReversed;
},
},
});
</script>
I have managed to change the palindrome function to return string if full name is a palindrome, however, task specifically requests to return a boolean value when palindrome function is initiated.
Any hints, advice? Please.
Edit
People dataset:
[
{
"id": 1,
"firstName": "Bo",
"lastName": "Bob",
"authorised": true,
"enabled": false,
"colours": [
{
"id": 1,
"name": "Red"
}
]
},
{
"id": 2,
"firstName": "Brian",
"lastName": "Allen",
"authorised": true,
"enabled": true,
"colours": [
{
"id": 1,
"name": "Red"
},
{
"id": 2,
"name": "Green"
},
{
"id": 3,
"name": "Blue"
}
]
},
{
"id": 3,
"firstName": "Courtney",
"lastName": "Arnold",
"authorised": true,
"enabled": true,
"colours": [
{
"id": 1,
"name": "Red"
}
]
},
{
"id": 4,
"firstName": "Gabriel",
"lastName": "Francis",
"authorised": false,
"enabled": false,
"colours": [
{
"id": 2,
"name": "Green"
}
]
},
{
"id": 5,
"firstName": "George",
"lastName": "Edwards",
"authorised": true,
"enabled": false,
"colours": [
{
"id": 2,
"name": "Green"
},
{
"id": 3,
"name": "Blue"
}
]
},
{
"id": 6,
"firstName": "Imogen",
"lastName": "Kent",
"authorised": false,
"enabled": false,
"colours": [
{
"id": 1,
"name": "Red"
},
{
"id": 2,
"name": "Green"
}
]
},
{
"id": 7,
"firstName": "Joel",
"lastName": "Daly",
"authorised": true,
"enabled": true,
"colours": [
{
"id": 2,
"name": "Green"
}
]
},
{
"id": 8,
"firstName": "Lilly",
"lastName": "Hale",
"authorised": false,
"enabled": false,
"colours": [
{
"id": 1,
"name": "Red"
},
{
"id": 2,
"name": "Green"
},
{
"id": 3,
"name": "Blue"
}
]
},
{
"id": 9,
"firstName": "Patrick",
"lastName": "Kerr",
"authorised": true,
"enabled": true,
"colours": [
{
"id": 2,
"name": "Green"
}
]
},
{
"id": 10,
"firstName": "Sharon",
"lastName": "Halt",
"authorised": false,
"enabled": false,
"colours": [
{
"id": 1,
"name": "Red"
},
{
"id": 2,
"name": "Green"
},
{
"id": 3,
"name": "Blue"
}
]
},
{
"id": 11,
"firstName": "Willis",
"lastName": "Tibbs",
"authorised": true,
"enabled": false,
"colours": [
{
"id": 1,
"name": "Red"
},
{
"id": 2,
"name": "Green"
},
{
"id": 3,
"name": "Blue"
}
]
}
]