Java Script/Vue.js

[Vue] Vue 복습문제 #0417수업 #1교시

웨일파도 2023. 4. 17. 10:11
반응형

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="index.css">
        <script src="js/jquery.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        
    </head>
    <body>      
        <div id="app">
            <!-- 버튼 클릭하면 클릭 횟수 증가 -->
            <div>
                클릭 횟수 : <span>{{cnt}}</span>번 입니다.
                <button @click = "plusCnt">클릭!</button>
            </div>
            <!-- 버튼 클릭하면 알람창 뜬 후 배경색 변경 -->
            <div id="text">
                버튼 이벤트2
                <button @click="fnAlert">클릭!</button>
            </div>
        </div>      
    </body>
    </html>
    <script>
        var app = new Vue({ 
        el: '#app',
        data: {
            cnt : 0
        }, methods: {
              plusCnt : function() {
                this.cnt++;
              },
              fnAlert : function() {
                alert("안녕하세요");
                document.getElementById("text").style.backgroundColor = "pink";
              }
        }
        , created: function () {

        }
    });
    </script>

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="index.css">
        <script src="js/jquery.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        
    </head>
    <body>
        <!-- input 창에 입력한 text가 '추가' 버튼을 누르면 출력되도록 하기
        그 다음 text을 input 창에 입력하면 기존 text 와 이어서 출력되도록 하기   -->
        <div id="app">
            <input type="text" v-model="txt" @keyup.enter="fnclick">
            <button @click="fnclick">추가</button>
            <div>{{board}}</div>
        </div>      
    </body>
    </html>
    <script>
        var app = new Vue({ 
        el: '#app',
        data: {
            board : "",
            txt : ""
        }, methods: {
            fnclick : function() {
                this.board = this.board + this.txt;
                this.txt = "";
            }
        }
        , created: function () {
            
        }
    });
    </script>

 

반응형