본문 바로가기

1.웹개발/VUE

vue & 인스턴스

인스턴스 뷰로 개발할 떄 필수로 생성해야 하는 코드

(객체지향 프로그래밍에서 클래스 구조로 할당된 실체)

new Vue();
const vm = new Vue();
console.log(vm);

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <!-- ... -->
  </div>

  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    // const options = 
    const vm = new Vue({
      el: '#app',
      data: {
        message: 'hi'
      },
      methods: {

      },
      created: function() {

      }
    });
  </script>
</body>
</html>

생성자 함수(대문자 암묵적동의)

function Person(name,job){
	this.name = name;
	this.job = job;
}

const p = new Person('heo', 'developer')
console.log(p)

뷰를 생성자 함수로 찍어내는 이유

api와 속성들을 미리 넣어둠


인스턴스에서 사용할 수 있는 속성 & API

 

el, template, data,methods,created,watch

반응형