screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Get last two Characters from string</h3> <p>String:{{str}}</p> <p>Get Last Two Character: {{lastTwoChars}}</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { str: 'hello world', }; }, computed: { lastTwoChars() { if (this.str && this.str.length >= 2) { return this.str.slice(-2); } else { return this.str; } }, }, }); </script> <style scoped> #app { background-color: #f2f2f2; padding: 10px; } h3 { color: #333; font-size: 24px; margin-bottom: 10px; } p { color: #666; font-size: 18px; margin-bottom: 5px; } p:last-of-type { font-weight: bold; } </style> </body> </html>