Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

vue 函数式组件如何获取dom?

这是函数式组件:

<template functional>
    <div>
        这是函数式组件
    </footer>
</template>

<script>
    export default {}
</script>

我要怎么样获取这个组件的dom?我需要把这个dom挂载到el-scrollbar里面,但是render出来的vnode的elm和componentInstance都是undefined,小白求解


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

函数式组件不会实例化,自然是没有那些实例属性的。

<template functional>
    <div id='xxx'>
        这是函数式组件
    </footer>
</template>

<script>
    export default {}
</script>

//通过获取id就可以获取到DOM元素了

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...