Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue js - pass data within two components in the same level

I have data that I need to pass from one component1 to another component2.

I don't use vuex or router.

Components tree:

-Parent
--Component1
--Component2

From first component1 I make ajax request, retrieving info and pushing to data.

board: [1,2,3,4,5]

And I need access that retrieved data in component2

Can I do It without vuex or router ?

Thank you :)

like image 717
Medf101 Avatar asked Mar 19 '26 19:03

Medf101


1 Answers

You could emit an event to parent from component1 having as parameters the updated board and in the parent one receive that and pass it through props to component2

In component1 :

this.$emit("sendToComp2",this.board);

in the parent component :

  <template>
  <component1  @sendToComp2="sendTo2"/>
  ...
  <component2 :boards="boards" />
  ....
  </template>


  data:{
    boards:[]
    },
  methods:{
       sendTo2(boards){
        this.boards=boards
          }
      }

component2 should have property called boards

  props:["boards"]
like image 120
Boussadjra Brahim Avatar answered Mar 21 '26 09:03

Boussadjra Brahim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!