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 Find and Replace to Textarea</h3> <textarea v-model="text"></textarea> <div> <input type="text" v-model="search" placeholder="Search"> <input type="text" v-model="replace" placeholder="Replace"> <button @click="replaceText">Replace</button> </div> </div> <script type="module"> const app = Vue.createApp({ data() { return { text: "", search: "", replace: "", } }, methods: { replaceText() { const escapedSearch = this.escapeRegExp(this.search); const regex = new RegExp(escapedSearch, "g"); if (!this.text.match(regex)) { alert("Search string not found in text."); return; } const confirmed = confirm(`Are you sure you want to replace "${this.search}" with "${this.replace}"?`); if (confirmed) { const newText = this.text.replace(regex, this.replace); this.text = newText; } }, escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } } }); app.mount('#app'); </script> <style scoped> /* Style the main container */ #app { max-width: 800px; margin: 0 auto; padding: 20px; } /* Style the text area */ textarea { width: 100%; height: 300px; font-size: 16px; padding: 10px; border-radius: 5px; border: 1px solid #ccc; margin-bottom: 20px; } /* Style the input and button container */ div>* { margin-right: 10px; } /* Style the search and replace inputs */ input[type="text"] { padding: 10px; font-size: 16px; border-radius: 5px; border: 1px solid #ccc; } /* Style the replace button */ button { background-color: #007bff; color: #fff; padding: 10px 20px; font-size: 16px; border-radius: 5px; border: none; cursor: pointer; } /* Style the replace button on hover */ button:hover { background-color: #0069d9; } </style> </body> </html>