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 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.

Quick-add: + add another resource

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.

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.

            
              body {
  margin: 10px;
}

button {
  margin-right: 5px;
}
            
          
!
            
              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
Loading ..................

Console