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">
  <v-app>
    
    <div>
      <v-banner color="grey lighten-1">
        <h3>既存オブジェクトにリアクティブなプロパティを追加するテスト</h3>
        <p>
          <a href="https://jp.vuejs.org/v2/guide/list.html#配列の変化を検出">
            https://jp.vuejs.org/v2/guide/list.html#配列の変化を検出
          </a>
        </p>
        <p>
          <v-chip small class="ma-2" color="teal" text-color="white">
            <v-avatar left>
              <v-icon>mdi-checkbox-marked-circle</v-icon>
            </v-avatar>結論
            </v-chip>push() pop() shift() unshift() splice() sort() reverse() で書き換えると幸せになれる
        </p>
        
        <template v-slot:actions>
          <v-chip outlined small class="ma-2" color="primary" >Vue {{ vueVersion }}</v-chip>
          <v-chip outlined small class="ma-2" color="primary" >Vuex {{ vuexVersion }}</v-chip>
          <v-chip outlined small class="ma-2" color="primary" >Vuetify {{ vuetifyVersion }}</v-chip> 
        </template>
        
      </v-banner>
    </div>
    
    <div class="my-2">
      <v-card shaped class="mx-auto" max-width="800">
        <v-card-title class="headline">NGパターン</v-card-title>
        <v-card-text>既存オブジェクトに新しいプロパティ(status)を追加してもリアクティブしない</v-card-text>
        <v-card shaped>
          <list-order :orders="orders" :is-enable="isEnable"></list-order>
          <br>
          <v-simple-table v-if="isEnable">
           <template v-slot:default>
             <thead>
               <tr class="grey lighten-1">
                 <th>Step</th>
                 <th>Command</th>
                 <th>Comment</th>
               </tr>
            </thead>
            <tbody>
              <tr>
                <td><v-btn @click="onClickInit" small>Step1</v-btn></td>
                 <td></td>
                 <td>データ初期化</td>
              </tr>
                <tr>
                <td><v-btn @click="onClickB1S2" small>Step2</v-btn></td>
                 <td>this.orders[0].status = 'Order confirmed'</td>
                 <td>1行目 Status だけを変更</td>
              </tr>
                <tr>
                 <td><v-btn @click="onClickB1S3" small>Step3</v-btn></td>
                  <td>this.orders[1].status = 'Order confirmed'</td>
                  <td>2行目 Status だけを変更</td>
              </tr>
                <tr>
                <td><v-btn @click="onClickB1S4" small>Step4</v-btn></td>
                  <td>
                    this.orders[0].name = 'Core i9-9980XE<br>
                    this.orders[0].status = 'Order confirmed'<br>
                   </td>
                 <td>1行目 Status は変更、Name だけ上書き</td>
              </tr>
                <tr>
                <td><v-btn @click="onClickB1S5" small>Step5</v-btn></td>
                  <td>
                   this.orders[0].name = 'Ryzen 9 3950X'<br>
                   this.orders[0].status = 'Order confirmed'<br>
                  </td>
                 <td>2行目 Status は変更、Name だけ上書き</td>
              </tr>
                <tr>
                <td><v-btn @click="onClickB1S6" small>Step6</v-btn></td>
                 <td>
                   this.orders[0] = {id: 1, name: 'Core i9-9980XE', quantity: 1, price: '$24,091', status:'Order confirmed'}
                 </td>
                 <td>1行目 Status は変更、残り 上書き</td>
              </tr>
                <tr>
                <td><v-btn @click="onClickB1S7" small>Step7</v-btn></td>
                 <td>
                   this.orders[1] = {id: 2, name: 'Ryzen 9 3950X', quantity: 1, price: '$749.99', status:'Order confirmed'}
                 </td>
                 <td>1行目 Status は変更、残り 上書き</td>
              </tr>
            </tbody>
          </template>
        </v-simple-table>
       </v-card>
     </v-card>
    </div>
  
    <div class="my-2">
      <v-card shaped class="mx-auto" max-width="800">
        <v-card-title class="headline">微妙パターン</v-card-title>
        <v-card-text>既存プロパティの値(違うものに変更)と一緒に変更してやるとリアクティブする</v-card-text>
        <v-card shaped>
          <list-order :orders="orders" :is-enable="isEnable"></list-order>
          <br>
          <v-simple-table v-if="isEnable">
           <template v-slot:default>
             <thead>
               <tr class="grey lighten-1">
                 <th>Step</th>
                 <th>Command</th>
                 <th>Comment</th>
               </tr>
            </thead>
            <tbody>
              <tr>
                <td><v-btn @click="onClickInit" small>Step1</v-btn></td>
                 <td></td>
                 <td>データ初期化</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickB2S2" small>Step2</v-btn></td>
                 <td>
                   this.orders[0].name = 'いんてる あとむ ぷろせっさ'<br>
                   this.orders[0].status = 'Processing'<br>
                 </td>
                 <td>1行目 Status を変更、Name も変更</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickB2S3" small>Step3</v-btn></td>
                 <td>
                   this.orders[1].name = 'えーえむでぃ あすろん'<br>
                   this.orders[1].status = 'Processing'<br>
                 </td>
                 <td>2行目 Status を変更、Name も変更</td>
              </tr>          
            </tbody>
          </template>
        </v-simple-table>
       </v-card>
     </v-card>
   </div>        
        
    <div class="my-2">
      <v-card shaped class="mx-auto" max-width="800">
        <v-card-title class="headline">OKパターン</v-card-title>
        <v-card-text>this.orders.splice(0, 1, data) でデータを書き換えるとリアクティブしてくれる</v-card-text>
       <v-card shaped>
          <list-order :orders="orders" :is-enable="isEnable"></list-order>
          <br>
          <v-simple-table v-if="isEnable">
           <template v-slot:default>
             <thead>
               <tr class="grey lighten-1">
                 <th>Step</th>
                 <th>Command</th>
                 <th>Comment</th>
               </tr>
            </thead>
            <tbody>
              <tr>
                <td><v-btn @click="onClickInit" small>Step1</v-btn></td>
                 <td></td>
                 <td>データ初期化</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickG2S2" small>Step2</v-btn></td>
                 <td>
                   let data = this.orders[0]<br>
                   data.status = 'Shipped'<br>
                   this.orders.splice(1, 1, data)<br>  
                 </td>
                 <td>spliceで1行目書換</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickG2S3" small>Step3</v-btn></td>
                 <td>
                   let data = this.orders[1]<br>
                   data.status = 'Shipped'<br>
                   this.orders.splice(1, 1, data)<br>
                  </td>
                 <td>spliceで2行目書換</td>
              </tr>          
            </tbody>
          </template>
        </v-simple-table>
       </v-card>
     </v-card>
   </div>           
      
    <div class="my-2">
      <v-card shaped class="mx-auto" max-width="800">
        <v-card-title class="headline">OKパターン</v-card-title>
        <v-card-text>this.$set(this.orders[0], 'status', 'Completed')でデータを書き換えるとリアクティブしてくれる</v-card-text>
        <v-card shaped>
          <list-order :orders="orders" :is-enable="isEnable"></list-order>
          <br>
          <v-simple-table v-if="isEnable">
           <template v-slot:default>
             <thead>
               <tr class="grey lighten-1">
                 <th>Step</th>
                 <th>Command</th>
                 <th>Comment</th>
               </tr>
            </thead>
            <tbody>
              <tr>
                <td><v-btn @click="onClickInit" small>Step1</v-btn></td>
                 <td></td>
                 <td>データ初期化</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickG4S2" small>Step2</v-btn></td>
                 <td>this.$set(this.orders[0], 'status', 'Completed')</td>
                 <td>set()で1行目書換</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickG4S3" small>Step3</v-btn></td>
                 <td>this.$set(this.orders[1], 'status', 'Completed')</td>
                 <td>set()で2行目書換</td>
              </tr>          
            </tbody>
          </template>
        </v-simple-table>
       </v-card>
     </v-card>
   </div>
      
    <div class="my-2">
      <v-card shaped class="mx-auto" max-width="800">
        <v-card-title class="headline">OKパターン</v-card-title>
        <v-card-text>v-ifで強制レンダリング</v-card-text>
<v-card shaped>
          <list-order :orders="orders" :is-enable="isEnable"></list-order>
          <br>
          <v-simple-table v-if="isEnable">
           <template v-slot:default>
             <thead>
               <tr class="grey lighten-1">
                 <th>Step</th>
                 <th>Command</th>
                 <th>Comment</th>
               </tr>
            </thead>
            <tbody>
              <tr>
                <td><v-btn @click="onClickInit" small>Step1</v-btn></td>
                 <td></td>
                 <td>データ初期化</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickG3S2" small>Step2</v-btn></td>
                 <td>
                   this.isEnable= false<br>
                   this.orders[0].status = 'Handling'<br>
                   this.$nextTick(() => (this.isEnable = true))<br>
                 </td>
                 <td>v-if false -> true で1行目書換</td>
              </tr>
              <tr>
                <td><v-btn @click="onClickG3S3" small>Step3</v-btn></td>
                 <td>
                   this.isEnable= false<br>
                   this.orders[1].status = 'Handling'<br>
                   this.$nextTick(() => (this.isEnable = true))<br>
                 </td>
                 <td>v-if false -> true で2行目書換</td>
              </tr>          
            </tbody>
          </template>
        </v-simple-table>
       </v-card>
     </v-card>
   </div>        
  </v-app>
</div>

<script type="text/x-template" id="tmpl-order">
  <v-card shaped>
    <v-simple-table v-if="isEnable">
      <template v-slot:default>
        <thead>
          <tr class="grey lighten-1">
            <th>Id</th>
            <th>Name</th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Status</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="order in orders" :key="order.id">
            <td>{{ order.id }}</td>
            <td>{{ order.name }}</td>
            <td>{{ order.quantity }}</td>
            <td>{{ order.price }}</td>
            <td>{{ order.status }}</td>
          </tr>
        </tbody>
      </template>
    </v-simple-table>
  </v-card>
</script>
              
            
!

CSS

              
                tbody tr:nth-of-type(even) {
  background-color: rgba(0, 0, 0, 0.0);
} 
tbody tr:nth-of-type(odd) {
  background-color: rgba(0, 0, 0, 0.05);
}
              
            
!

JS

              
                const store = new Vuex.Store({
  state: {
    subTitle: 'Vuex2.0.0',
    dataSet: {
      isEnable: true,
      orders:  []
    },
  },
  getters: {
    orders (state) {
      return state.dataSet.orders
    }
  },
  actions: {
    SET_ORDER({commit}, data)  {
      commit('SET_ORDER', data)
    }
  },
  mutations: {
    SET_ORDER (state, data) {
      state.dataSet.orders = data
    }
  }              
})

Vue.component('list-order', {
  props: ['isEnable', 'orders'],
  template: '#tmpl-order'
})

new Vue({
  el: '#app',
  strict: true,
  store,
  vuetify: new Vuetify(),
  created () {
    this.onClickInit()
  },
  data: {
    title: 'Vuetify 2.x',
    subTitle: 'Vuex2.0.0',
    isEnable: true
  },
  computed: {
    orders: {
      get () { return this.$store.state.dataSet.orders },
      set (data) { this.$store.dispatch('SET_ORDER', data) }
    },
    vueVersion: {
      get () { return Vue.version }
    },
    vuexVersion: {
      get () { return Vuex.version }
    },
    vuetifyVersion: {
      get () { return Vuetify.version }
    } 
  },
  methods: {
    onClickInit () {
      this.orders = [
        {id: 1, name: 'Core i9-9980XE', quantity: 1, price: '$24,091'},
        {id: 2, name: 'Ryzen 9 3950X', quantity: 1, price: '$749.99'},
      ]
    },
    onClickB1S2() {
      this.orders[0].status = 'Order confirmed'
      alert(JSON.stringify(this.orders, undefined, 4))
    },
    onClickB1S3() {
      this.orders[1].status = 'Order confirmed'
      alert(JSON.stringify(this.orders, undefined, 4))
    },
    onClickB1S4() {
      this.orders[0].name = 'Core i9-9980XE'
      this.orders[0].status = 'Order confirmed'
      alert(JSON.stringify(this.orders, undefined, 4))
    },
    onClickB1S5() {
      this.orders[1].name = 'Ryzen 9 3950X'
      this.orders[1].status = 'Order confirmed'
      alert(JSON.stringify(this.orders, undefined, 4))
    },
    onClickB1S6() {
      this.orders[0] = {id: 1, name: 'Core i9-9980XE', quantity: 1, price: '$24,091', status:'Order confirmed'}
      alert(JSON.stringify(this.orders, undefined, 4))
    },
    onClickB1S7() {
      this.orders[1] = {id: 2, name: 'Ryzen 9 3950X', quantity: 1, price: '$749.99', status:'Order confirmed'}
      alert(JSON.stringify(this.orders, undefined, 4))
    },
    onClickB2S2() {
      this.orders[0].name = 'いんてる あとむ ぷろせっさ'
      this.orders[0].status = 'Processing'
    },
    onClickB2S3() {
      this.orders[1].name = 'えーえむでぃ あすろん'
      this.orders[1].status = 'Processing'
    },
    onClickG2S2() {
      let data = this.orders[0]
      data.status = 'Shipped'
      this.orders.splice(0, 1, data)
    },
    onClickG2S3() {
      let data = this.orders[1]
      data.status = 'Shipped'
      this.orders.splice(1, 1, data)
    },
    onClickG3S2() {
      this.isEnable= false
      this.orders[0].status = 'Handling'
      this.$nextTick(() => (this.isEnable = true))
    },
    onClickG3S3() {
      this.isEnable= false
      this.orders[1].status = 'Handling'
      this.$nextTick(() => (this.isEnable = true))
    },
    onClickG4S2() {
      this.$set(this.orders[0], 'status', 'Completed')
    },
    onClickG4S3() {
      this.$set(this.orders[1], 'status', 'Completed')
    },
   }
});
              
            
!
999px

Console