A
A
August Milovich2019-08-08 18:34:34
Vue.js
August Milovich, 2019-08-08 18:34:34

How to pass a variable to another vue component?

Good afternoon, there is such a question, how to transfer the value of a variable from one component to another neighboring one? The difficulty is that this should happen on click. I have a button in one component that opens the menu, the second component is the menu itself. I read about props, but he also receives a variable from the very beginning, and it becomes undefined.
Panel with button:

export default{
        name: "left-aside",
        isBarMenuClicked: false, // эту переменную нужно передать
        methods: {
            openLeftMenu: function(){
                this.isBarMenuClicked = true;
            }
        }
    }

Menu:
export default {
        name: "boards-menu",
        data() {
            return {
                isLeftMenuShowed: true, // вторая переменная, отвечающая за меню
            }
        },
        methods: {
            closeLeftMenu: function () {
                this.isLeftMenuShowed = false
            }
        },
        props: [
            'isBarMenuClicked'
        ]
    }

Also, how can you get rid of two variables? The menu component has a variable that closes the menu, and to open the menu, you have to use the second one passed from the button panel component. Somehow it's not really pretty.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gilfy, 2019-08-08
@CodeInMyHeart

https://vuex.vuejs.org/ru/guide/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question