<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <title>Document</title> </head> <body> <h2>Vue </h2> <div id="app"> <p>금지문자는 {{forbiddenText}}</p> <textarea v-model="inputText"></textarea> </div> <script> new Vue({ el:"#app", data:{ forbiddenText:'씨댕', inputText:'' }, watch :{ inputText(){ const pos =this.inputText.indexOf(this.forbiddenText); if(pos >-1){ alert(this.forbiddenText + " 는 입력할 수 없습니다."); this.inputText =this.inputText.substr(0,pos); } } } }); </script> </body> </html>
댓글 ( 4)
댓글 남기기