Answer the question
In order to leave comments, you need to log in
How to connect instances in vue3?
I started looking at the documentation for vue3. I did not quite understand how to connect two different instances. For example:
<div id="app">
<h2>Первый инстанс</h2>
<h2>{{ title }}</h2>
<button @click="title = 'update title'">update title</button>
</div>
<hr>
<div id="app2">
<h2>Второй инстанс</h2>
<h2>{{ title }}</h2>
<button @click="updateFirstTitle">updateFirstTitle</button>
</div>
<script src="https://unpkg.com/[email protected]"></script>
<script>
const MyApp = Vue.createApp({
data() {
return {
title: 'Hello I am Vue!',
}
},
})
const MyApp2 = Vue.createApp({
data() {
return {
title: 'Hello from vue2!!!'
}
},
methods: {
updateFirstTitle() {
MyApp.title = 'Update from second app'
console.log('=====', MyApp)
}
}
})
MyApp.mount('#app') //новое создание инстанса
MyApp2.mount('#app2') //новое создание инстанса
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question