vue中$el是什么,vue中封装模态框

export default {
    
    
  name: COMPONENT_NAME,
  props: {
    
    
    // 是否显示
    visible: {
    
    
      type: Boolean,
      default: false
    },
    // 标题
    title: {
    
    
      type: String,
      default: 'Modal'
    }
  },
  mounted() {
    
    
    console.log('mounted', this);
    console.log('document.body.appendChild(this.$el)', this.$el);
    document.body.appendChild(this.$el);
  },
  destroyed() {
    
    
    if (this.$el && this.$el.parentNode) {
    
    
      this.$el.parentNode.removeChild(this.$el);
    }
  },
  methods: {
    
    
    closeModal() {
    
    
      this.$emit('close');
    }
  }
};

在vue中封装modal弹出框,见到了如下代码,就比较好奇$el到底指向的是什么

经过验证:指向的正是本组件的elemnt
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43131046/article/details/124153234
今日推荐