I’m havin a parent component, let’s say “1”, it has 2 child components, “2” and “3”, each one of this components has one child component, “4” for “2” and “5” for “3”. So the question is how to pass state from the child component “5” to last component “4” ? Probably should I use composables approach? Could you show me an example?
How to organise sending data with script setup vue 3? With probably composables touch
99 Views Asked by Ron At
2
There are 2 best solutions below
3
Nobsyde
On
You don't need to use Pinia, you can create a "store" as simply as this:
// on a new storeName.js file
import { ref } from 'vue'
export const myStore = ref('')
and then import myStore on whichever component might need it, either to update it (e.g. on your component 5) or just to check its value (e.g. on your component 4). Once you change the value of myStore anywhere, it will be updated on every component. That's it!
Related Questions in JAVASCRIPT
- Angular Show All When No Filter Is Supplied
- Why does a function show up as not defined
- I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
- Set "More" "Less" font size
- Using pagination on a table in AngularJS
- How to sort these using Javascript or Jquery Most effectively
- how to fill out the table with next values in array with one button
- State with different subviews
- Ajax jQuery firing multiple time display event for the same result
- Getting and passing MVC Model data to AngularJS controller
- Disable variable in eval
- javascript nested loops waiting for user input
- .hover() seems to overwrite .click()
- How to sort a multi-dimensional array by the second array in descending order?
- How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?
Related Questions in VUE.JS
- jqBootstrapValidation() is not a function
- In Vue.js, change value of specific attribute for all items in a data array
- Vue.js - How to handle all elements with the same selector?
- How can I use Elixir + Vueify?
- Bind function on newly created element
- Vue.js Passing data to content scope
- Updating the DOM with change in an object (vue.js) - binding not working?
- websocket + vuejs: screen flickering, visible mustache code
- Vue.js nested v-repeat: How to access parent $index inside child?
- VueJS - trouble understanding .$set and .$add
- Difference between two similar functions, why is one working and the other not
- Display unescaped HTML in Vue.js
- Mouseover or hover vue.js
- vuejs: Trying to focus the input using v-el directive
- Vue.js component issue
Related Questions in VUE-PROPS
- Vue Prop Sync on multiple levels (TypeScript & JavaScript & ClassStyle)
- Route component as props in Vue
- How to change contents of a column in each row of a table without using a props in Vue.js (Element-ui)?
- Vue Js: Props not being passed to component, only showing on page refresh
- Passing prop value after switching tabs
- Understanding Props Passed to router-view for Vue Child Component, Prop Data Not Rendering
- In Vue, when do child components render?
- Add condition to .sync in vue.js
- Vue composition typescript access props value in another props validation
- How to pass props in Quasar 2 Vue 3 Composition API table?
- Vue doenst update modelValue inside watch
- Why the props in a Child component are empty in Quasar, Vue 3 app?
- How to open a page with a router link with vue 3 and Quasar?
- How can I pass form data from a nested component to a outer component using Vue2 and Nuxt2
- Errors typing props using interface in Vue 3 (Vue: Untyped function calls may not accept type arguments.)
Related Questions in EMIT
- Input of the reduce phase is not what I expect in Hadoop (Java)
- Send event to client, from server, and then disconnect the socket (from server)
- Angular2 observe an attribute in a service for changes
- large json response emitted from celery, not reaching flask
- countdown in socket.io does not start at the same time
- Properly emit property
- send EventEmitter from child component <ng-content>
- How to implement emit to work in a synchronous manner
- Is socket.io emit callback appropriate?
- scope.$on is not working when created inside a directive
- EventEmitter emit is not working in angular 4
- broadcast and emit does not work with ng-router?
- Vuejs $emit didn't trigger parent's function on callback
- Return values using EventEmitter angular2
- VueJs Tree recursive elements emits to parent
Related Questions in COMPOSABLE
- How to change @DrawableRes parameter to Drawable in @Compose function?
- declaration file for custom hook vue3 composable
- A better way to handle http request and responses in Nuxt 3
- How to record a video of a Jetpack Compose @Composable function without blocking UI thread?
- How do I make kotlin composable update when a global value changes
- Vue3/Pinia: Using Pinia store inside a composable throws TypeError within pinia core code
- Unexpected gap between Text lines in jetpack compose
- State Management Issue | Android Jetpack Compose
- Vue, Vitest and MSW: Mocking and testing a GraphQL query result in composable not possible
- Room through DAO fails inside composable in NavHost
- Column not taking all available space from it's parent Column
- How to efficiently compose business logic with a Transaction Script pattern using an ORM?
- Vuejs: can't make a composable universal
- How to organise sending data with script setup vue 3? With probably composables touch
- Manually clearing the view model in composable Component in Kotlin
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 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?
If your components are used only together there's a standard way to provide data for a component hierarchy:
https://vuejs.org/guide/components/provide-inject
Also it's more flexible than using a store or a shared module variable (suggested by Nobsyde) since you can swap the top most component with another with the same provides and your descendant will work with them too. Your components should only agree with what provides they will work together.
You can set default values for injected provides so your components could work outside the hierarchy or with some changed provides' list. So your components could be context sensitive.
Another way to share data between sibling components is scoped slots: How to use data from one component in another component vuejs