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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                h1 為什麼畫面沒有隨資料更新 — 深入 Vue 響應式原理筆記(陣列部分)
hr
p.quotation 此篇文章為整理自 #[a(href="https://cn.vuejs.org/v2/guide/list.html#注意事项") Vue 官網 列表渲染注意事項] 之筆記


#change-by-array-index(v-cloak)
    h3 利用索引值變更 index 0 的值(無法響應式變化)
    input(type="text" v-model="animal")
    button(v-on:click="changeAnimal") Change Animal
    ul
        li(v-for="item in animals" v-bind:key="item") {{ item }}
    button(v-on:click="$forceUpdate()") forceUpdate
    

#change-by-splice(v-cloak)
    h3 方法一:利用 splice 達到響應式變化
    input(type="text" v-model="animal")
    button(v-on:click="changeAnimal") Change Animal
    ul
        li(v-for="item in animals" v-bind:key="item") {{ item }}
    
    
#change-by-set(v-cloak)
    h3 方法二:利用 vm.$set 達到響應式變化
    input(type="text" v-model="animal")
    button(v-on:click="changeAnimal") Change Animal
    ul
        li(v-for="item in animals" v-bind:key="item") {{ item }}
              
            
!

CSS

              
                $green: #41CEC0;
$vue: #41b883;
$blue: #35495e;
$purple: #A53860;
$red: #C63647;
$yellow: #FFDF2C;
$orange: #E96900;

[v-cloak]{
  display: none;
}


              
            
!

JS

              
                
/**
 * change by array index
 **/
new Vue({
    el: '#change-by-array-index',
    data: {
        animal: "",
        animals: ['<YOURAnimal>', 'cat', 'penguin', 'bird', 'rabbit']
    },
    methods: {
        changeAnimal(){
            // 當利用陣列索引直接設置值時
            this.animals[0] = this.animal
        }
    }
})

/**
 * change by splice
 **/
new Vue({
    el: '#change-by-splice',
    data: {
        animal: "",
        animals: ['<YOURAnimal>', 'cat', 'penguin', 'bird', 'rabbit']
    },
    methods: {
        changeAnimal(){
            // 利用 arr.splice(startIndex, deleteCount, addItem)
            this.animals.splice(0, 1, this.animal)
        }
    }
})


/**
 * change by set
 **/
new Vue({
    el: '#change-by-set',
    data: {
        animal: "",
        animals: ['<YOURAnimal>', 'cat', 'penguin', 'bird', 'rabbit']
    },
    methods: {
        changeAnimal(){
            // 利用 vm.$set(array, index, value) 方法
            this.$set(this.animals, 0, this.animal)
        }
    }
})
              
            
!
999px

Console