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

              
                #app
    h1 關於 Vue Computed 的那些小細節
    hr
    p #[a(href="https://pjchender.blogspot.tw/2017/05/vue-computed-getter-setter.html") 文章連結:Computed 中 getter 和 setter 觸發的時間點]
    #computed-getter-basic(v-cloak) 
        h3.title-border 一般情況 computed getter 被觸發的時間點
        form.pure-form
            input(type="text" v-model="firstName")
            input(type="text" v-model="lastName")
        p fullName: {{ fullName }}
    #computed-getter-exception-without-render(v-cloak) 
        h3.title-border 資料更新但不會觸發 getter (沒有初次 render)
        p 當畫面沒有 render 到這個 computed 的屬性時
        form.pure-form
            input(type="text" v-model="firstName")
            input(type="text" v-model="lastName")
        p firstName: {{ firstName }} #[br] lastName: {{ lastName }}
    hr
    #computed-setter-basic(v-cloak) 
        h3.title-border 一般情況 computed setter 被觸發的時間點
        form.pure-form
            input(type="text" v-model="fullName")
        p firstName: {{ firstName }} #[br] lastName: {{ lastName }}
    #computed-setter-without-getter(v-cloak) 
        h3.title-border computed setter 被觸發不必然會觸發 getter
        form.pure-form
            input(type="text" v-model="fullName")
        p fullName: {{fullName}}
    hr
    p(style="color:darkred") 以下為錯誤內容,僅供留存
    #computed-setter-deep-object(v-cloak) 
        h6.title-border computed setter 不會監控到物件的內部(錯誤示範)
        form.pure-form
            input(type="text" v-model="fullName.firstName")
            input(type="text" v-model="fullName.lastName")
        p firstName: {{firstName}}
        p lastName: {{lastName}}
              
            
!

CSS

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

[v-cloak]{
  display: none;
}


              
            
!

JS

              
                // computed-getter-basic 
new Vue({
    el: '#computed-getter-basic ',
    data: {
        firstName: 'PJ',
        lastName: 'Chen'
    },
    computed: {
        fullName () {
            console.log('computed getter')
            return this.firstName + ' ' + this.lastName
        }
    },
    updated () {
        console.log('updated')
    }
})

// computed-getter-exception-without-render
new Vue({
    el: '#computed-getter-exception-without-render',
    data: {
        firstName: 'PJ',
        lastName: 'Chen'
    },
    computed: {
        fullName () {
            console.log('computed getter')
            return this.firstName + ' ' + this.lastName
        }
    },
    updated () {
        console.log('updated')
    }
})


// computed-setter-basic
new Vue({
    el: '#computed-setter-basic',
    data: {
        firstName: 'PJ',
        lastName: 'Chen'
    },
    computed: {
        fullName: {
            get () {
                console.log('computed getter')
                return this.firstName + ' ' + this.lastName
            },
            set (value) {
                console.log('computed setter')
                this.firstName = value.split(' ')[0]
                this.lastName = value.split(' ')[1]
            }
        }
    },
    updated () {
        console.log('updated')
    }
})



// computed-setter-basic
new Vue({
    el: '#computed-setter-without-getter',
    data: {
        firstName: 'PJ',
        lastName: 'Chen'
    },
    computed: {
        fullName: {
            get () {
                console.log('computed getter')
                return this.firstName + ' ' + this.lastName
            },
            set (value) {
                console.log('computed setter')
                this.firstName = value.split(' ')[0]
                this.lastName = value.split(' ')[1]
            }
        }
    },
    updated () {
        console.log('updated')
    }
})




// computed-setter-deep-object
const vmDeepObject = new Vue({
    el: '#computed-setter-deep-object',
    data: {
        firstName: 'PJ',
        lastName: 'Chen'
    },
    computed: {
        fullName: {
            get () {
                console.log('computed getter')
                return {
                    firstName: this.firstName,
                    lastName: this.lastName
                }
            },
            set (value) {
                console.log('computed setter')
                this.firstName = value.split(' ')[0]
                this.lastName = value.split(' ')[1]
            }
        }
    },
    updated () {
        console.log('updated')
    }
})
              
            
!
999px

Console