screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Get Text from div</h3> <div ref="myDiv">This is some text</div> <button @click="getText">Get Text</button> <p v-if="divText">{{ divText }}</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { divText: '' } }, methods: { getText() { const myDiv = this.$refs.myDiv if (myDiv) { const textContent = myDiv.innerHTML.trim() if (textContent) { this.divText = textContent } else { this.divText = '' } } } } }); </script> </body> </html>