Vue - when and why using $el(Vue - 何时以及为什么使用 $el)
问题描述
我在这里找到了这个答案:https://stackoverflow.com/a/50431015/11735826我想知道为什么在这里使用 .$el ,以及为什么没有 el 元素它不能工作?
I've found this answer here: https://stackoverflow.com/a/50431015/11735826 and i wonder why .$el was used here, and also why does it not work without the el element?
推荐答案
当你在html标签上使用ref
属性时,this.$refs.modal会返回DOM-element
.
when you use ref
attribute on the html tag, the DOM-element is returned by this.$refs.modal
.
当你在模板标签上使用 ref
属性时,会返回组件实例,所以 this.$refs.modal.$el
直接返回 DOM 元素.请参阅 https://vuejs.org/v2/api/#vm-el
when you use ref
attribute on the template tag, the component instance is returned, so this.$refs.modal.$el
returns directly the DOM element. See https://vuejs.org/v2/api/#vm-el
这篇关于Vue - 何时以及为什么使用 $el的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Vue - 何时以及为什么使用 $el


基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01