Answer the question
In order to leave comments, you need to log in
How to pass variable between vue.js components?
There is a main app.vue template. Represents a header with a button and pull-up content from child components in router-view
<template>
<div id="app">
<CreateButton
:link = "createLink"/>
<router-view class="text-center mt-12 container"></router-view> //здесь отображаются дочерние компоненты
</div>
</template>
<script>
import CreateButton from './components/includes/CreateButton'
export default {
name: 'App',
components: {
CreateButton
},
data() {
return {
createLink: 'UserCreate',
}
},
}
</script>
CreateButton
, here it is:<template>
<router-link
:to="{ name: link }"
class="btn btn-success">+</router-link>
</template>
<script>
export default {
props: ['link']
}
</script>
data() {
return {
createLink: 'DeleteUser',
}
},
Answer the question
In order to leave comments, you need to log in
for simple buses - https://alligator.io/vuejs/global-event-bus/
Vuex - for the rest of the
PS
, the essence of events here is that in one component you listen to the event (changing the name of the link)
and in the other you initiate this event. Norm. works in conjunction father-son. If the nesting is greater (grandfather-dad-son) - then it is more difficult => Vuex
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question