![]() |
Vue.js is a JavaScript framework used in building powerful and beautiful user interfaces. The key feature of Vue.js is its component-based architecture that allows the developers to create reusable and modular components. In this article, we will learn how to pass value from one child component to another in VueJS. There are sometimes when we need to pass data from one child component to another, either for communication or to update the state of the components. Steps to Create Vue App:Step 1: Install Vue modules using the below npm command npm install vue Step 2: Use Vue JS through CLI. Open your terminal or command prompt and run the below command. npm install --global vue-cli Step 3: Create the new project using the below command vue init webpack myproject Step 4: Change the directory to the newly created project cd myproject Project Structure:The following project structure will be generated after completing the above-required steps: Approach 1: Using PropsIn the first approach, we will first pass the value from the first child component to the parent component using props, and after which we will pass it from the parent component to the second child component. Example: Below example demonstrates the passing of value from one child component to another using props in vuejs.
HTML
HTML
Output: Approach 2: Using Event BusIn the second approach, we will create a shared service or event bus using a separate Vue instance to facilitate communication between components. Example: Below example demonstrates the passing of value from one child component to another using the event bus in vuejs.
HTML
HTML
Output: |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |