Why can't the variables defined in data be accessed in the $on of Vue

the code is as follows:

import headerVue from "./components/header.vue";
import bodyVue from "./components/body.vue";
import footerVue from "./components/footer.vue";
import connector from "./components/connector.js";

export default {
  data: function() {
    return {
      textInfo: "This is Father Div",
      listenText: ["a","B"]
    };
  },
  methods: {
    listen: function() {
      connector.$on("phone", function(msg) {
        // this.listenText.push(msg);
        console.log(app.listenText);   // this.listenTextundefined
        // console.log(msg);
      });
    }
  },
  props: [],
  components: {
    headerVue: headerVue,
    bodyVue: bodyVue,
    footerVue: footerVue
  }
};

in the above code, when using the parent component to listen for the value passed by the child component, after the child component passes the value, the parent component"s $on event is triggered, and it is possible to output msg directly, but the variables defined in data cannot be accessed here. What"s going on?

Nov.24,2021

you are using the traditional function callback. You need to consider the scope. It is recommended to directly use the arrow function

.
connector.$on("phone", (msg) => {
        console.log(this.listenText); 
      });
Menu