cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              const TeaItem = Vue.extend({
  props: {
    name: {
      type: String,
      default: ''
    }
  },
  template:
    '<div class="TeaItem">' +
      '<div>{{name}}</div>' +
    '</div>'
});

const componentRoot = new Vue({
  data: function(){
    return {
      selectedItemList: [],
      teas: [
        {
          type: ['blacktea'],
          name: 'イングリッシュ ブレックファースト'
        },
        {
          type: ['greentea'],
          name: 'シルバームーン'
        },
        {
          type: ['greentea'],
          name: 'トーキョー シンガポール'
        },
        {
          type: ['blacktea', 'smokytea'],
          name: 'スモーキー アールグレイ'
        },
      ]
    }  
  },
  
  template:
    '<div>' +
      '<button @click="toggleSelected( \'blacktea\')" class="waves-effect waves-light btn">' +
        '<template v-if="includes(\'blacktea\')">&#10004;</template>' +
        '紅茶' +
      '</button>' +
      '<button @click="toggleSelected( \'greentea\')" class="waves-effect waves-light btn">' +
        '<template v-if="includes(\'greentea\')">&#10004;</template>' +
        '緑茶' +
      '</button>' +
        '<button @click="toggleSelected( \'smokytea\')" class="waves-effect waves-light btn">' +
        '<template v-if="includes(\'smokytea\')">&#10004;</template>' +
        '燻製茶' +
      '</button>' +
      '<template v-if="noSelected">' +
        '<p>絞り込みが可能です</p>' +
      '</template>' +
      '<template v-else>' + 
        '<p>{{selectedItemList}}を選択中</p>' + 
      '</template>' +
      '<template v-for="tea in teas">' +
        '<template v-if="includesAll(tea.type)">' +
          '<tea-item :name="tea.name"></tea-item>' +
        '</template>' +
      '</template>' +
    '</div>',
  
  methods: {
    //選択状態をトグルする
    toggleSelected: function(type){
      const isSelected = this.includes(type);
      //配列内にtypeがなければ追加
      if(!isSelected){
        this.$data.selectedItemList.push(type);
      }else{
        //配列内にtypeがあれば取り除く
        //配列から指定の要素を取り除いた、新しい別の配列「filtered」を作る
        const filtered = this.$data.selectedItemList.filter(function(el){
          return el !== type;
        });
        this.$data.selectedItemList = filtered;
      }
    },
    //選択している内容にtypeが含まれていればtrueを返す
    includes: function(type){
      return this.$data.selectedItemList.indexOf(type) !== -1;
    },
    //選択している種類全てが、引数のtypesに含まれていればtrueを返す
    includesAll: function(types){
      let matched = true;
      this.$data.selectedItemList.forEach(function(selected){
        const found = types.some(function(type){
          return type === selected;
        });
        if(!found){
          matched = false;
        }
      });
      return matched;
    }
  },
  
  computed: {
    noSelected: function(){
     if(this.$data.selectedItemList.length === 0){
       return true;
     }else{
       return false;
     }
    }
  },
  
  components: {
    TeaItem: TeaItem
  }
});

componentRoot.$mount('#MyAppRoot');
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console