简体   繁体   中英

How to get DOM element of current Vue component?

当我在vue commponent中的某个方法内部并想要使用一些dom操作(通过jquery)时,我需要让DOM元素与我的组件相对应(特别是在我在页面上有很多组件实例时 - 我需要'分别对每一个工作 - 所以我不能仅使用jquery选择器检测DOM元素而没有技巧......)

Just by this (in any method in "methods"):

let domElement = this.$el;

:)

But remember this is valid as long as your component is not a Fragment Instance ie it has a single root HTML tag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM