Issue with rendering initial item from API in Nativescript-vue TabView

Issue:

Currently, I am developing a NativeScript-Vue application in which I am utilizing TabView Items to generate tabs. The tab title and content are populated from a JSON data file through a loop.

Challenge:

The first tabView item is not displaying any information initially. I have noticed that in order to view the data, I need to click on other tabs first and then return to the first tab. Only then the items become visible.

Here is the code snippet used to create tabs using NativeScript-Vue:

<TabView 
    android:tabBackgroundColor="#ffffff"
    android:tabTextColor="#ffa801"
    android:selectedTabTextColor="#f53b57"
    androidSelectedTabHighlightColor="#ffffff"
    androidTabsPosition="Bottom"> 
    <TabViewItem v-for="subcategory in subcategories"  :title="subcategory.name" >
        
            <FlexboxLayout>
            <Label :text="subcategory.name" />

        </FlexboxLayout>
    </TabViewItem>
</TabView> 

Subcategories is an array fetched from the API in the JSON format with the following structure.

[
    {
        "id": 3,
        "category_id": 1,
        "name": "Vegetarian",
        "description": "Vegetarian",
        "items": [
            {
                "id": 6,
                "subcategory_id": 3,
                "name": "Salad",
                "description": "test",
                "price": "100",
                "status": "1",
            }
        ]
    },
    {
        "id": 2,
        "category_id": 1,
        "name": "Sea Food",
        "description": "sea food",
        "items": [
            {
                "id": 4,
                "subcategory_id": 2,
                "name": "some item",
                "description": "desc",
                "price": "100",
                "status": "1",
            }
        ]
    }
]

Attempted Solutions:

  1. https://github.com/nativescript-vue/nativescript-vue/issues/515

Even after exploring the provided solutions, the issue persists

[Update] Sample Script:

            <script >
            import axios from 'axios';
            import Login from "./Login";
            import FoodItems from "./FoodItems"
            import SubCategories from "./parts/SubCategories"
            import CategoryButtons from "./parts/CategoryButtons"
            import Popular from "./parts/Popular"
            
            // import Items from "./Items"
        export default {
            components: {SubCategories, CategoryButtons, Popular},
            props: ['parentCategory'],
            data() {
            return {
                subcategories: [],
                populars: [],
                categories:this.$store.getters.getCategories,       
            }
            },
            mounted(){


                axios({
                    method:"GET",
                    "url":this.$store.state.apiUrl+"categories/"+this.parentCategory.id+"/subcategories",
                    headers:{
                        'Accept': 'application/json',
                    'Authorization': 'Bearer ' + this.$store.getters.getToken,
                    }
                }).then(
                    response =>
                    {    
                        // 
                        this.subcategories =response.data.fooditems;
                        this.populars = response.data.popularitems;
                        // console.log(response.data.popularitems);
                    }, error => {
                        console.error(error);
                    }
                );
            },
            methods: {
                
                    
                
                checkToken() {
                
                    this.$store.commit("loadFromStorage");
                    if(!this.$store.getters.getToken) { this.$navigateTo(Login, { clearHistory: true })  }
                },

                goToShowCase(args) {
                    //   console.log(args);
                        this.$navigateTo(Showcase,    
                            { 
                            props: 
                            { parentCategory: args }
                            });           
                    }


            

                    
            }
        }
        </script>

Update 2:

I have replicated the issue on the NativeScript playground platform. Link to the example:

Thank you for your assistance!

Answer №1

Is the problem resolved by including a :key in your iterated elements?

<TabViewItem v-for="subcategory in subcategories" 
            :key="some_unique_value_between_them" 
            :title="subcategory.name" 
             loaded="mainContentLoaded">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery is failing to properly render dynamic content data identifiers

Need help with a dynamic HTML div <a data-id="17" onclick="getcustomer();"> <div class="note note-success"> <h4 class="block">A</h4> <p>Email : <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

What could be the reason for the malfunction of the select (mongoose query)?

I'm trying to retrieve a User's highest score post. To accomplish this, I am querying the Post model and looking for posts where their user._id matches the author in the post. Everything is functioning correctly in this regard. However, my goal ...

Adding to array using v-model

Just starting out with Vue.js, I'm delving into developing a shop application using Vue and Webpack. My product data is stored in a json file, and I am rendering them with the help of v-for. My goal is to have the ability to add products to a cart by ...

What is the best way to display the current time (generated through JavaScript) within a designated div element?

During my JavaScript studies, I stumbled upon the following code snippet: function printTime() { var d = new Date(); var hours = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); document.body.innerHTML = hours+":"+mins+":"+sec ...

What is the best way to access a particular property of an object?

Currently, I am successfully sending data to Mongo and storing user input information in the backend. In the console, an interceptor message confirms that the data is received from MongoDB. However, I am struggling to extract specific properties such as th ...

Expand Menu Options (jQuery)

Currently facing a jQuery problem that I can't seem to figure out. I've set up a menu with submenu elements and want to toggle the content height by clicking on menu items. The issue arises when clicking on another item causes the content to coll ...

Ensuring button is inactive when API value is zero in Vue

Presented here are a set of buttons that provide live probability odds for a particular event, allowing users to make selections based on the updated data fetched from an API every minute. https://i.stack.imgur.com/uGdld.png If the probability displayed ...

Reference to a method from a child component in Vue returns an undefined method when using v-for loop

I am facing an issue with a child component and a button that triggers a method within it: <div v-for="(i,index) in user.usertype.max_user" :key="index" class="d-flex w-50"> <vue-user-profiles ref="userProfileComponent"></vue ...

The Vue.js countSubcategories() function is designed to return a Promise object

The countSubcategories() function is currently returning [object Promise] instead of the row counts of mapped subcategories. This code snippet uses vue.js and Laravel. Do you have any suggestions on how to fix this issue? <div v-for="(cat,index) in ca ...

Can Vue composites make a function become reactive?

Is there a way to create a composite function that allows consumers to provide a reference to a function? In mixins, you could simply call the consumer method if it existed. Here is my attempt at making it work, but it seems like method1 is not reactive. I ...

Updating a computed property in VueJS through refactoring

Looking to enhance my computed property that currently functions as expected. The objective is for it to return true when any of the 3 data properties are empty strings and also when any of the strings equal "n/a": appNamesInvalid() { ...

Unable to utilize a third setState function due to the error message indicating an excessive number of re-renders

My current challenge involves setting an initial state for my Hook. I have a clickable element that changes the state between Decreasing and Increasing upon click, and this part is functioning properly. However, I encounter an issue when attempting to defi ...

Custom options titled MUI Palette - The property 'primary' is not found in the 'TypeBackground' type

I am currently working on expanding the MUI palette to include my own custom properties. Here is the code I have been using: declare module '@mui/material/styles' { interface Palette { border: Palette['primary'] background: Pa ...

Issue with Select2: When using a remote select2 control, the tab key press does not allow for the selection of the highlighted

I have set up select2 to load ajax data into select2 based on the example provided in this link Load ajax data into select2. In the example, I can type text, use arrow keys to navigate, and then hit tab to select the highlighted item. However, in my case, ...

Creating a component that fetches asynchronous data and renders it server-side

In the context of server-side rendering (SSR), it is known that only the router component can request async data using the asyncData method. However, I have a main component (which is not the router component) where I also need to fetch some async data for ...

What could be causing the lack of change in direction for the initial function call?

There appears to be an issue with image(0) and image(1) in this array that I can't quite understand. The console output shows: i=5; div class="five" id="slides" i=0; div class="one" id="slides" i=1; div class= ...

Iterating through a JSON object and an array

I've been attempting to iterate through a JSON object but I'm struggling with it. Below is the JSON object I need to work with. This JSON data will be fetched from another website, and my goal is to loop through it to extract certain details. ...

Sequential jQuery AJAX requests triggering in an incorrect sequence

One challenge I am facing involves a select list with bundles of short texts. Upon selecting a specific bundle, the texts are displayed in two tables. Each table row has a "Delete" icon to remove a text from the bundle. I am aiming to refresh both the tabl ...

Variable remains unchanged by method

I am currently working on an app that utilizes the user's webcam. In case navigator.getUserMedia fails, I need to change the error variable to display the appropriate error message instead of the stream output. Since I am new to Vue, please bear with ...

Is there a way to keep track of changes in multiple dropdowns without having to create a separate JavaScript function for each one

I'm looking for a way to dynamically add more dropdowns as my website grows without having to keep adding new functions to the JavaScript code. Is there a solution for this? Currently, I can add additional functions to the JavaScript like this: ...