1

Hi I am new to vue and I am wondering how to data-bind from one component to another.

export default {
  name: 'dashboard-sidebar',
  methods: {
    monthChange: function (event) {
      var selectedMonth = $("#sel1").val();
      this.$root.$emit('changed', selectedMonth);

    },
    dashboardReportsChange(value){
      var selectedDashboard = value;
      this.$root.$emit('click', selectedDashboard);

    }
  }
}

I want to get the value of the variables I declare and data-bind it into another component in my app.

export default {
  components:{
    dashboardsidebar
  },
  mounted() {
    this.$root.$on('changed', (selectedMonth) => {
      console.log(selectedMonth);
    })
    this.$root.$on('click', (selectedDashboard) => {
      console.log(selectedDashboard)
    })

  }
}

This is my other component.

1
  • You can check vuex for state management vuex.vuejs.org Commented Aug 9, 2018 at 3:21

1 Answer 1

1

You can't bind data between components. What you can do;

  1. You can use VueX, which is also what I would recommend.
  2. If components have parent-child relation, you can use props.
  3. Or you can use Events or a global EventBus and create methods for accessing the data in the specific component.

I hope this helps you somehow.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.