What is the problem with the vue element-ui component getting the new Vue value?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.bootcss.com/qs/6.5.2/qs.min.js"></script>
</head>

<body>
<div id="app">
    <h1>{{title}}</h1>
    <mycomponent></mycomponent>
</div>
<script>
 Vue.component("mycomponent",{
    template: "<div><el-popover placement="top-start" title="" width="200" trigger="hover" content=",,,"> <el-button slot="reference">hover </el-button></el-popover><el-button @click="click"></el-button></div>",
    data () {
      return {
        message: "hello world"
      }
    },
    mounted(){
      console.log("")
      console.log(this.message)
      // console.log(app.title)
    },
    methods:{
      click(){
        console.log("")
        console.log(app.title)
      }
    }
  })
  
  var app = new Vue({
    el: "-sharpapp",
    data: {
      title:""
    },
  })
</script>
</body>
</html>
The

code is as follows:
1, new Vue is defined as app
2, data has title value as "main title"
3, mycomponent component click method execution, console.log (app.title) can run
4, mycomponent component mounted execution, console.log (app.title) will report an error
solution? Thank you

May.27,2022

The main reason for

is that you called app in mounted, while the app object has not yet been formed, and Vue.component () executes before new Vue (). According to the specification, component registration should be done before the Vue instance is created, because you may use the component you just created in new Vue (), so be sure to create it before you use it.

if you have to call in mounted, you can only use setTimeout to add the code that is about to be executed to the queue.

mounted(){
  console.log("")
  console.log(this.message)
  setTimeout(() => {
    console.log(app.title)
  }, 0)
},
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea85a8-47ca3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea85a8-47ca3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?