获取您自己的 Vue 服务器
App.vue
InfoBox.vue
main.js
 
<template>
  <h2>Example $root Object</h2>
  <p>The 'text' data property can be reached and manipulated directly from a child component by the use of the $root object.</p>
  <pre>{{ text }}</pre>
  <info-box />
</template>

<script>
export default {
  data() {
    return {
      text: 'Initial text in the root component.'
    }
  }
}
</script>

<style>
pre {
  background-color: lightgreen;
  padding: 5px;
}
</style>                  
<template>
  <div>
    <h3>Change Text</h3>
    <p>Click the button to toggle the text in the PRE tag of the root component.</p>
    <button v-on:click="this.$root.text='Hello!'">Change text in root</button>
  </div>
</template>

<style scoped>
div {
  border: solid black 1px;
  padding: 10px;
  width: 250px;
}
</style>                  
import { createApp } from 'vue'

import App from './App.vue'
import InfoBox from './components/InfoBox.vue'

const app = createApp(App)
app.component('info-box', InfoBox)
app.mount('#app')
                  
https://127.0.0.1:5173/