2019년 3월 1일 금요일

vue 연습

  <body>  
   <div id="app">  
     <p>{{togglehiding}}</p>  
     <p v-if="togglehiding==1"> v if New p tag</p>  
     <p v-else-if="togglehiding==2"> v-else-if -2 New p tag</p>  
     <p v-else-if="togglehiding==3"> v-else-if -3 New p tag</p>  
     <p v-else-if="togglehiding==4"> v-else-if -4 New p tag</p>  
     <p v-else-if="togglehiding==5"> v-else-if -5 New p tag</p>  
     <p>  
     <button @click="togglehiding=!togglehiding">clickme</button>  
     <button @click="plus">plus ++</button>  
     </p>  
   </div>    
   <script type='text/javascript'>  
   var vm = new Vue({  
     el:'#app',  
     data:{  
       message:true,  
       togglehiding:1  
     },  
     methods:{  
       sayhi:function(v){   
         alert(v)  
       },  
       plus:function(){  
         this.togglehiding++  
       }        
     }  
   })  
   </script> 
 
 


커스텀 이벤트

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        h1,h2,h3,h4,h5,h6,div,p,span{font-size:36px; font-family: helvetica; padding:0; margin:0;}
        .comp_root{background:red; color:white;}
        #app{background:orange; padding:25px; color:blue}
    </style>
    <script type="text/javascript" src='../vue.js'>
    export default {
        
    }
    </script>
</head>
<body>
    <div id="app">

      <h1>Parent DIV</h1>     
      <comp v-on:relay='allocate'> </comp>
      <hr>
      <p>{{content1}}</p>
      <hr>
      <p>{{content2}}</p>     

    </div>  

    <template id="temp">
      <div class="comp_root">
        <h2>Component</h2>
        <input v-model='message1'>
        <input v-model='message2'>
        <button v-on:click='send'>Send data</button>
      </div>
    </template>  

</body>    
<script type='text/javascript'>

    var vm = Vue.component('comp', {
      template:'#temp',
      data:function(){
        return{
          message1:'저장된 �"시지1',
          message2:'저장된 �"시지2'
        }
      },
      props:[],
      methods:{
        send:function(){
          this.$emit('relay', this.message1, this.message2)
        },
        allocate:function(v1,v2){
            this.content1 =v1,
            this.content2 =v2
        }
      },
    })

    var vm = new Vue({
      el:'#app',
      data:{
        content1:'컨텐트1',
        content2:'컨텐트2'

      }
    })   
</script>
    

</html>

댓글 없음: