screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Create Element Dynamically</h3> <button @click="addParagraph">Add paragraph</button> <div ref="paragraphContainer"></div> </div> <script type="module"> const app = Vue.createApp({ methods: { addParagraph() { const newParagraph = document.createElement('p') newParagraph.style.color = 'red' newParagraph.style.fontSize = '18px' newParagraph.textContent = 'This is a dynamically created paragraph.' newParagraph.addEventListener('click', () => { alert('Paragraph clicked!') }) this.$refs.paragraphContainer.appendChild(newParagraph) } }, }) app.mount('#app') </script> </body> </html>