i’m trying to get the total result length but i’m not getting anything in my template
this my script
data() {
return {
searchResults: [],
totalResults: [],
}}
const response = await axios.post(
"http://localhost:5000/api/search",
searchData
);
this.searchResults = response.data.Response.Results; // Set the search results in the component's data // Retrieve the traceId from the response
const nestedResults = response.data.Response.Results;
const totalResults = nestedResults[0].length;
console.log("Total Results:", totalResults);
this is my console i’m getting totalResults
Total Results: 12
this my template
<p>Total Results: {{ totalResults }}</p>
template returns this
Total Results: []
i dont get anything in my template please how can i go about this
>Solution :
First off you’re initializing a variable that should be a number, with an empty array. You should have:
data() {
return {
searchResults: [],
totalResults: 0,
}}
Second of all you’re not assigning the value to the correct totalResults, you’re simply declaring a new variable. To assign the value you should use this.totalResults. Therefore
this.totalResults = nestedResults[0].length;