Vue 中获取元素内容的方法
在 Vue 中,有几种方法可以获取元素中的内容:
.textContent
.textContent
属性获取元素中所有包含的文本内容,包括换行符和文本节点。
<code><template><div id="my-element"> Hello, world! <br> This is some text. </div> </template><script> export default { mounted() { const element = this.$refs.myElement; console.log(element.textContent); // 输出:Hello, world! // This is some text. } } </script></code>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。