Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app">
  
  <!-- 유니크 키가 없는 배열 -->
  <select>
    <option v-for="item in list">{{ item }}</option>
  </select>
  
  <!-- 리터럴에 직접 v-for 적용 -->
  <p v-for="item in 3">{{ item }} 번째 P </p>
  
  <!-- 리터럴에 직접 & 배열사용 -->
  <p v-for="item in [1, 5, 10]">{{ item }}</p>
  
  <!-- 문자열에 v-for 적용-->
  <p v-for="item in text">{{ item }}</p>
  
  
  <!-- key는 반복 렌더링에서도 유니크한 key속성을 부여하는것이 권장된다 -->
   <ul>
    <li v-for="(mob, idx) in monster" v-bind:key="mob.id">
      [ id : {{mob.id}} ] [ name: {{mob.name}} ]  [ HP: {{mob.hp}} ]
      <strong v-if="mob.hp > 300"> 강하다!</strong>
      <button v-on:click="mobAttack(idx)">attack</button>
      <button v-on:click="mobDelete(idx)" v-bind:class="{'del':true}">delete</button>
    </li>
  </ul>
  
  <figure>
    <div>몹 추가</div>
    이름 : <input type="text" v-model="addMonsterName">
    HP : <input type="text" v-model="addMonsterHp">
    <button v-on:click="mobAdd">add</button>
  </figure>
  
</div>




              
            
!

CSS

              
                strong{
  color: red;
}
.del{
  margin-left: 20px;
}
              
            
!

JS

              
                const data = {
  list : ['리스트1', '리스트2', '리스트3'],
  text : 'TEST',
  monster : [
    { id: 1, name: '슬라임', hp: 100 },
    { id: 2, name: '고블린', hp: 200 },
    { id: 3, name: '드래곤', hp: 500 }
  ],
  addMonsterName : '',
  addMonsterHp : 0
}

const app = new Vue({
  el : '#app',
  data : data,
  methods : {
    
    mobAdd : function(){
      //리스트 내부에서 가장 큰 id값 추출
      const max = this.monster.reduce(function(a,b){
         return a > b.id ? a : b.id;
      }, 0);
      this.monster.push({
        id: max + 1,
        name : this.addMonsterName,
        hp : this.addMonsterHp
      }) 
    },
    mobDelete : function(idx){
      //배열의 splice 메서드로 제거
      this.monster.splice(idx, 1);
    },
    mobAttack : function(idx){
      this.monster[idx].hp -= 10; // HP 10 감소
    }
  },
})

              
            
!
999px

Console