Vue 인스턴스

모든 Vue 앱은 Vue() 함수로 새 Vue 인스턴스를 만드는 것부터 시작한다.

var vm = new Vue({
    // 옵션
});

속성과 메서드

각 Vue 인스턴스에 대해 data 객체에 있는 모든 속성을 프록시 처리한다.

// 데이터 객체
var data = { a: 1 }

// Vue 인스턴스에 대해 데이터 객체를 추가
var vm = new Vue({
    data: data
});

// 동일한 객체를 참조
console.log(vm.a === data.a); // => true

// 속성 설정은 원본 데이터에도 영향을 미침
vm.a = 2;
console.log(data.a); // => 2

// 반대로도 동일
data.a = 3;
console.log(vm.a); // => 3;

Vue 인스턴스 라이프사이클

<script>
export default {
    beforeCreate() {
        console.log("call beforeCreate")
    },
    created() {
        console.log("call created")
    },
    beforeMount() {
        console.log("call beforeMount")
    },
    mounted() {
        console.log("call mounted")
    },
    beforeUpdate() {
        console.log("call beforeUpdate")
    },
    updated() {
        console.log("call updated")
    },
    beforeDestroy() {
        console.log("call beforeDestroy")
    },
    destroyed() {
        console.log("call destroyed")
    }
}
</script>