V
V
Vitaly2018-09-15 13:09:13
Vue.js
Vitaly, 2018-09-15 13:09:13

How to pass data between Vue components?

app.js file:

window.Vue = require('vue');
import VueResource from 'vue-resource';
Vue.use(VueResource);
import Vuex from 'vuex';
Vue.use(Vuex);
Vue.component('comment-box', require('./components/CommentBox.vue'));
Vue.component('info-box', require('./components/InfoBox.vue'));
const app = new Vue({
    el: '#app'
});

InfoBox.vue
<template>
    <div :class="[{ isActive }, snackbars]" id="form-output-global">
        {{message}}
    </div>
</template>

How to declare globally these variables in order to change them from other components... For example, in CommentBox.vue do something like:
methods: {
            show(message){
                isActive = true,
                message = сообщение отправлено
            }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy, 2018-09-15
@kiukishenkaec

Thanks to all ! Found here https://habr.com/post/332628/ an example. What I needed!

R
Rasul Turganov, 2018-11-12
@rasult22

Or pass it to child components through props through a unidirectional connection, and pass it to the parent through events. Or use the VueX store, and get data using getters, and change using mutations.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question