• {{ ite" />
    • {{ ite" />
      • {{ ite"/>
        DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        I need to send an id from read component to update component. The id must be obtained by function updateItem(). But id is not sent to the child pag

        15 Views Asked by Alessandro de Almeida At 23 March 2024 at 19:52 2025-11-09T17:43:17.651000

        The id is obtaind correctly by function updateItem(id)

        <template>
          <UpdateView :itemId="itemId"/>
            <ul>
              <li v-for="item in items" :key="item.id">
                {{ item.name }}: {{ item.description }}
                <img :src="item.photo_url" alt="Country Image" />
                <button @click="deleteItem(item.id)">Delete</button>
                <button @click="updateItem(item.id)">Update</button>
              </li>
            </ul>
          </template>
          
          <script setup>
            import { ref, onMounted, provide } from 'vue'
            import { supabase } from '../supabase'
            import { useRouter } from 'vue-router'
            import UpdateView from './UpdateView.vue'
        
            const items = ref([])
            const itemId = ref(null)
            const router = useRouter()
          
            provide('itemId', itemId)
          
            async function getItems() {
              const { data } = await supabase.from('tabela1').select()
              items.value = data
            }
          
            async function deleteItem(id) {
              await supabase.from('tabela1').delete().eq('id', id)
              getItems() // Atualiza a lista após deletar o item
            }
          
            function updateItem(id) {
              itemId.value = id
              router.push({ name: 'update' }) // Redireciona para a rota de atualização
              console.log(itemId.value)
            }
          
            onMounted(() => {
              getItems()
            })
          </script>
        
        

        This page must receive the id, but it not happens

        <script setup>
          import { ref, onMounted } from 'vue'
          import { supabase } from '../supabase'
        
          const item = ref(null)
          const props = defineProps({
            itemId: {
              type: Number,
              required: true
            }
          })
        
          onMounted(async () => {
            const { data } = await supabase.from('tabela1').select().eq('id', props.itemId.value)
            item.value = data[0]
            console.log(props.itemId)
          })
        </script>
        
        <template>
          <div v-if="item">
            <label for="name">Nome</label>
            <input id="name" v-model="item.name" />
        
            <label for="description">Descrição</label>
            <input id="description" v-model="item.description" />
        
            <button @click="updateItem">Atualizar</button>
          </div>
        </template>
        
        

        If I put the number 2 in the place of props.itemId.value in the update page It works corectly, but if I put the number 2 in the place of id in itemId.value = id in the read page, It don't work I don't know what is happening

        vuejs3 vue-component
        Original Q&A
        0

        There are 0 best solutions below

        Related Questions in VUEJS3

        • Problems with matter.js and i18n in vue.js
        • Vue3 Suspense Parent > Child Animation
        • Problem sending HTTP post request from VUE to ASP.NET Core MVC project
        • How to import a local image in vuex store without using axios
        • Vue TransitionGroup not working properly because of css transition
        • tsParticles onHover not working on my Vue Project
        • Vue.js Event Emitted in Child Component Not Detected by Parent Component
        • Resource URI is recognised but page wont load and browser throws 404, route:list says the route exist
        • vue 3 phaser and spine.js - Uncaught TypeError: Cannot read properties of undefined (reading 'data')
        • Inertia/Vue: keep getting props undefined error
        • How to make source dynamic for vue-i18n
        • How do I dynamically handle endless nested routes with Nuxt 3?
        • Vue 3 router changing <routing-view/> but not URL
        • Creating base pinia action that can be mixed-in to several stores with typescript
        • Vue.js - define v-model with defineProps and defineModel

        Related Questions in VUE-COMPONENT

        • tsParticles onHover not working on my Vue Project
        • How to dynamically switch between two images onclick in Vue.js
        • How can i display elements?
        • How to toggle a v-if
        • Problems in Validations via Web Service in a Vue 3 Application
        • vuetify data-table-server binding paging properties
        • I need to send an id from read component to update component. The id must be obtained by function updateItem(). But id is not sent to the child pag
        • Vuejs child component props does not update when parent component update props value
        • Handling a this.$router.replace(href); in vue 2
        • diferrence between new vue & vue.createapp
        • Is it possible to return a value from the $emit?
        • Passing object with reactive properties as a prop triggers child component onUpdated hook when updating parent component state
        • Dynamic image loading to not work in Vue project!! On no dynamic everything loads correct
        • Error Element Plus Dynamic Tab component in Vue 3
        • vue-hotel-datepicker is not working for PST — Pacific Standard Time

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates