screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.22/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Js Count occurrences of a specific substring in Text</h3> <p class="message">{{ message }}</p> <p class="target-word">The word "<span class="target-word">{{ targetWord }}</span>" appears {{ countOccurrences(message, targetWord) }} times.</p> </div> <script type="module"> const app = Vue.createApp({ data() { return { message: 'This is an example message that contains the word example multiple times.', targetWord: 'example' } }, methods: { countOccurrences(str, word) { const lowercaseStr = str.toLowerCase(); const lowercaseWord = word.toLowerCase(); return lowercaseStr.split(lowercaseWord).length - 1; } } }); app.mount('#app'); </script> <style scoped> /* Style the app container */ #app { display: flex; flex-direction: column; align-items: center; font-family: Arial, sans-serif; background-color: #f9f9f9; padding: 20px; border: 1px solid #ccc; border-radius: 10px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } /* Style the heading */ h3 { font-size: 28px; color: #333; margin-bottom: 20px; } /* Style the message paragraph */ p.message { font-size: 20px; color: #666; line-height: 1.5; margin-bottom: 20px; text-align: center; max-width: 80%; } /* Style the target word paragraph */ p.target-word { font-size: 20px; color: #333; line-height: 1.5; text-align: center; } /* Style the target word */ .target-word { color: #007bff; font-weight: bold; } </style> </body> </html>