Vue.extend cannot display template content

use Vue.extend (require (". / message.vue")); to import a message component into body. For some reason, only the template in the empty div,message.vue of el has been imported. What"s the problem?

src/components/toast/index.js

import Vue from "vue";

let MyMsgConstructor = Vue.extend(require("./message.vue"));

let instance;

let message = function (msg) {
    instance = new MyMsgConstructor({
        el: document.createElement("div"),
        data: {
            message: msg,
            visible: true
        }
    });
    
    document.body.appendChild(instance.$el);
    return instance;
};


export default message;

src/components/toast/message.vue

 <template>
    <transition name="el-message-fade">
        <div v-show="visible" class="my-msg">{{message}}</div>
    </transition>
</template>

<script>
    export default {
        data() {
            return {
                message: "",
                visible: true
            }
        },
        methods: {
            close() {
                setTimeout(() => {
                    this.visible = false;
                }, 2000)
            },
        },
        mounted() {
            this.close();
        }
    }
</script>

main.js

import message from "./components/toast/index.js"
Vue.$message = Vue.prototype.$message = message;

use

openToast() {
    this.$message("test");
}
Mar.03,2021

  //dom
  instance.vm = instance.$mount()

import toast from'@ / components/common/toast/toast.vue';

const ToastConstructor = Vue.extend (toast);

it can be solved in this way. Import

first.

as to why, Vue.extend (require ('. / message.vue')); can't do this. I can't find the problem for the time being

Menu