screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.26/dist/vue.global.js"></script> </head> <body> <h3>Vue Disable text selection</h3> <div id="app"> <button @click="toggleSelect">Toggle text selection</button> <p :class="{ 'no-select': !allowSelect }"> This text {{ allowSelect ? 'can' : 'cannot' }} be selected. </p> </div> <script> const app = Vue.createApp({ data() { return { allowSelect: false, }; }, computed: { selectCSS() { return this.allowSelect ? 'auto' : 'none'; }, }, methods: { toggleSelect() { this.allowSelect = !this.allowSelect; }, }, }); app.mount('#app'); </script> <style scoped> .no-select { -webkit-user-select: none; /* Safari */ -ms-user-select: none; /* IE 10 and IE 11 */ user-select: none; /* Standard syntax */ } </style> </body> </html>