SlideShare une entreprise Scribd logo
1  sur  16
Vue.js 입문
데이터와 메소드
Instance options : data, methods, computed
메소드
(data 옵션과 유사합니다!)
methods란 옵션 속성에 메소드들로 정의된 객체를 전달
<div id="app">
<h1>
반지름이 {{ radius }}cm인 둘레의 길이는 {{ circumference(radius) }}cm이고,
원의 넓이는 {{ circleArea(radius) }}cm<sup>2</sup>입니다.
</h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var dataOptionsObject = { radius: 10 };
var methodsOptionObject = {
circumference: function( r ){
return Math.round( 2*Math.PI*r *100)/100;
},
circleArea: function( r ){
return Math.round( Math.PI*r*r *100)/100;
}
};
var vueConfigOptions = {
el: '#app',
data: dataOptionsObject,
methods: methodsOptionObject
};
var app = new Vue( vueConfigOptions );
</script>
TODO 결과 화면 추가
데이터와 메소드의 바인딩
데이터 옵션과 메소드 옵션은 그대로
Vue 인스턴스의 데이터와 메소드가 됩니다!
<div id="app">
<h1>웹 브라우저의 JS 콘솔을 열어 Vue 인스턴스를 확인하세요</h1>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
data1: "dummy", data2: "dummy", data3: "dummy", data4: "dummy", data5: "dummy"
},
methods: {
testMethod1(){ // ES6 문법 == testMethod1: function(){
return "dummy"
},
testMethod2(){ return "dummy" }, testMethod3(){ return "dummy" },
testMethod4(){ return "dummy" }, testMethod5(){ return "dummy" }
}
});
console.log( app );
</script>
메소드의 바인딩과 화살표 함수
메소드를 화살표 함수(ES6+)로 정의할 때는
lexical this 특성에 주의해야 합니다.
데이터 옵션의 특징
데이터는 Vue 인스턴스에게서 감시(?!)당합니다.
데이터가 변경되면 화면을 다시 그립니다.
(Render)
<div id="app">
<h1>dataPropertyIsReactive = "{{ dataPropertyIsReactive }}"</h1>
<button onclick="changeData();">변해라!</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: { dataPropertyIsReactive: "dummy" }
});
function changeData(){
const now = new Date();
app.dataPropertyIsReactive = now.toLocaleString();
};
</script>
계산된 속성 (Computed)
메소드 수행 결과가 캐싱됩니다.
메소드 속성처럼 정의하고 데이터 속성처럼 사용합니다.
<div id="app">
<h1>{{ computedProperty }}</h1>
<h1>{{ computedProperty }}</h1>
<h1>{{ computedProperty }}</h1>
<button onclick="changeData();">변해라!</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
computed: {
computedProperty(){
console.log("recompute?!");
return new Date();
}
}
});
function changeData(){
app.computedProperty = new Date();
};
</script>
TODO 결과 화면 추가
그리고 계산된 속성은
메소드 내부에
데이터 옵션으로 정의된 프로퍼티를 사용하면
계산된 속성 또한 반응형이 됩니다.
<div id="app">
<h1>{{ computedProperty }}</h1>
<button onclick="changeData();">변해라!</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
int: 10
},
computed: {
computedProperty(){
console.log("recompute?!");
return this.int + 1;
}
}
});
function changeData(){
app.int = Math.round(Math.random()*10);
};
</script>
TODO 결과 화면 추가

Contenu connexe

Tendances

개발자의 컴퓨터
개발자의 컴퓨터개발자의 컴퓨터
개발자의 컴퓨터jaehyok Song
 
2009 응용수학2 과제
2009 응용수학2 과제2009 응용수학2 과제
2009 응용수학2 과제Kyunghoon Kim
 
Webframeworks angular js 세미나
Webframeworks angular js 세미나Webframeworks angular js 세미나
Webframeworks angular js 세미나WebFrameworks
 
Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료joonseokkim11
 
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기Jeado Ko
 
vine webdev
vine webdevvine webdev
vine webdevdcfc1997
 
Naver api for android
Naver api for androidNaver api for android
Naver api for androidSangon Lee
 
자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기Jeado Ko
 

Tendances (10)

개발자의 컴퓨터
개발자의 컴퓨터개발자의 컴퓨터
개발자의 컴퓨터
 
Nest js 101
Nest js 101Nest js 101
Nest js 101
 
2009 응용수학2 과제
2009 응용수학2 과제2009 응용수학2 과제
2009 응용수학2 과제
 
Webframeworks angular js 세미나
Webframeworks angular js 세미나Webframeworks angular js 세미나
Webframeworks angular js 세미나
 
Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료Opinion 프로젝트 발표 자료
Opinion 프로젝트 발표 자료
 
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
[XECon+PHPFest 2014] jQuery 개발자에서 AngularJS 개발자 되기
 
vine webdev
vine webdevvine webdev
vine webdev
 
Naver api for android
Naver api for androidNaver api for android
Naver api for android
 
자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기
 
ch04
ch04ch04
ch04
 

Similaire à Vue.js 입문 03 데이터와 메소드

[Week14] D3.js_Scale and Axis (보충자료)
[Week14] D3.js_Scale and Axis (보충자료)[Week14] D3.js_Scale and Axis (보충자료)
[Week14] D3.js_Scale and Axis (보충자료)neuroassociates
 
Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발Jay Park
 
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로Jaeseung Ha
 
20150212 c++11 features used in crow
20150212 c++11 features used in crow20150212 c++11 features used in crow
20150212 c++11 features used in crowJaeseung Ha
 
Node.js and react
Node.js and reactNode.js and react
Node.js and reactHyungKuIm
 
overview of spring4
overview of spring4overview of spring4
overview of spring4Arawn Park
 
파이썬 데이터베이스 연결 1탄
파이썬 데이터베이스 연결 1탄파이썬 데이터베이스 연결 1탄
파이썬 데이터베이스 연결 1탄SeongHyun Ahn
 
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive Elasticsearch
 
처음 접하는 Oozie Workflow, Coordinator
처음 접하는 Oozie Workflow, Coordinator처음 접하는 Oozie Workflow, Coordinator
처음 접하는 Oozie Workflow, CoordinatorKim Log
 
[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVC[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVCAnselmKim
 

Similaire à Vue.js 입문 03 데이터와 메소드 (13)

[Week14] D3.js_Scale and Axis (보충자료)
[Week14] D3.js_Scale and Axis (보충자료)[Week14] D3.js_Scale and Axis (보충자료)
[Week14] D3.js_Scale and Axis (보충자료)
 
Nodejs express
Nodejs expressNodejs express
Nodejs express
 
Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발
 
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
[NDC2015] C++11 고급 기능 - Crow에 사용된 기법 중심으로
 
20150212 c++11 features used in crow
20150212 c++11 features used in crow20150212 c++11 features used in crow
20150212 c++11 features used in crow
 
Node.js and react
Node.js and reactNode.js and react
Node.js and react
 
One-day-codelab
One-day-codelabOne-day-codelab
One-day-codelab
 
overview of spring4
overview of spring4overview of spring4
overview of spring4
 
파이썬 데이터베이스 연결 1탄
파이썬 데이터베이스 연결 1탄파이썬 데이터베이스 연결 1탄
파이썬 데이터베이스 연결 1탄
 
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
 
처음 접하는 Oozie Workflow, Coordinator
처음 접하는 Oozie Workflow, Coordinator처음 접하는 Oozie Workflow, Coordinator
처음 접하는 Oozie Workflow, Coordinator
 
[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVC[스프링 스터디 3일차] @MVC
[스프링 스터디 3일차] @MVC
 
Node.js 심화과정
Node.js 심화과정Node.js 심화과정
Node.js 심화과정
 

Plus de 승빈이네 공작소

토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3승빈이네 공작소
 
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2승빈이네 공작소
 
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1승빈이네 공작소
 
Google Calendar API - PHP 연동하기
Google Calendar API - PHP 연동하기Google Calendar API - PHP 연동하기
Google Calendar API - PHP 연동하기승빈이네 공작소
 
Firebase for web (웹개발을 위한 파이어베이스) 4 Storage
Firebase for web (웹개발을 위한 파이어베이스) 4 StorageFirebase for web (웹개발을 위한 파이어베이스) 4 Storage
Firebase for web (웹개발을 위한 파이어베이스) 4 Storage승빈이네 공작소
 
Firebase for web (웹개발을 위한 파이어베이스) 3 Real-Time Database
Firebase for web (웹개발을 위한 파이어베이스) 3 Real-Time DatabaseFirebase for web (웹개발을 위한 파이어베이스) 3 Real-Time Database
Firebase for web (웹개발을 위한 파이어베이스) 3 Real-Time Database승빈이네 공작소
 
Firebase for web (웹개발을 위한 파이어베이스) 2 Authentication
Firebase for web (웹개발을 위한 파이어베이스) 2 AuthenticationFirebase for web (웹개발을 위한 파이어베이스) 2 Authentication
Firebase for web (웹개발을 위한 파이어베이스) 2 Authentication승빈이네 공작소
 
Firebase for Web (웹개발을 위한 파이어베이스) 1 Hosting
Firebase for Web (웹개발을 위한 파이어베이스) 1 HostingFirebase for Web (웹개발을 위한 파이어베이스) 1 Hosting
Firebase for Web (웹개발을 위한 파이어베이스) 1 Hosting승빈이네 공작소
 

Plus de 승빈이네 공작소 (19)

토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 3
 
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 2
 
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1
토이 프로젝트를 위한 속성 RDB(MySQL) 스터디 1
 
Vue.js 입문 04 조건부 랜더링
Vue.js 입문 04 조건부 랜더링Vue.js 입문 04 조건부 랜더링
Vue.js 입문 04 조건부 랜더링
 
Git 코드랩 스터디 4
Git 코드랩 스터디 4Git 코드랩 스터디 4
Git 코드랩 스터디 4
 
Git 코드랩 스터디 3
Git 코드랩 스터디 3Git 코드랩 스터디 3
Git 코드랩 스터디 3
 
Git 코드랩 스터디 2
Git 코드랩 스터디 2Git 코드랩 스터디 2
Git 코드랩 스터디 2
 
Git 코드랩 스터디 1
Git 코드랩 스터디 1Git 코드랩 스터디 1
Git 코드랩 스터디 1
 
ES6 for Node.js Study 5주차
ES6 for Node.js Study 5주차ES6 for Node.js Study 5주차
ES6 for Node.js Study 5주차
 
ES6 for Node.js Study 4주차
ES6 for Node.js Study 4주차ES6 for Node.js Study 4주차
ES6 for Node.js Study 4주차
 
ES6 for Node.js Study 3주차
ES6 for Node.js Study 3주차ES6 for Node.js Study 3주차
ES6 for Node.js Study 3주차
 
ES6 for Node.js Study 2주차
ES6 for Node.js Study 2주차ES6 for Node.js Study 2주차
ES6 for Node.js Study 2주차
 
ES6 for Node.js Study
ES6 for Node.js StudyES6 for Node.js Study
ES6 for Node.js Study
 
겜냥이 어플 활용 가이드
겜냥이 어플 활용 가이드겜냥이 어플 활용 가이드
겜냥이 어플 활용 가이드
 
Google Calendar API - PHP 연동하기
Google Calendar API - PHP 연동하기Google Calendar API - PHP 연동하기
Google Calendar API - PHP 연동하기
 
Firebase for web (웹개발을 위한 파이어베이스) 4 Storage
Firebase for web (웹개발을 위한 파이어베이스) 4 StorageFirebase for web (웹개발을 위한 파이어베이스) 4 Storage
Firebase for web (웹개발을 위한 파이어베이스) 4 Storage
 
Firebase for web (웹개발을 위한 파이어베이스) 3 Real-Time Database
Firebase for web (웹개발을 위한 파이어베이스) 3 Real-Time DatabaseFirebase for web (웹개발을 위한 파이어베이스) 3 Real-Time Database
Firebase for web (웹개발을 위한 파이어베이스) 3 Real-Time Database
 
Firebase for web (웹개발을 위한 파이어베이스) 2 Authentication
Firebase for web (웹개발을 위한 파이어베이스) 2 AuthenticationFirebase for web (웹개발을 위한 파이어베이스) 2 Authentication
Firebase for web (웹개발을 위한 파이어베이스) 2 Authentication
 
Firebase for Web (웹개발을 위한 파이어베이스) 1 Hosting
Firebase for Web (웹개발을 위한 파이어베이스) 1 HostingFirebase for Web (웹개발을 위한 파이어베이스) 1 Hosting
Firebase for Web (웹개발을 위한 파이어베이스) 1 Hosting
 

Vue.js 입문 03 데이터와 메소드

  • 1. Vue.js 입문 데이터와 메소드 Instance options : data, methods, computed
  • 2. 메소드 (data 옵션과 유사합니다!) methods란 옵션 속성에 메소드들로 정의된 객체를 전달
  • 3. <div id="app"> <h1> 반지름이 {{ radius }}cm인 둘레의 길이는 {{ circumference(radius) }}cm이고, 원의 넓이는 {{ circleArea(radius) }}cm<sup>2</sup>입니다. </h1> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> var dataOptionsObject = { radius: 10 }; var methodsOptionObject = { circumference: function( r ){ return Math.round( 2*Math.PI*r *100)/100; }, circleArea: function( r ){ return Math.round( Math.PI*r*r *100)/100; } }; var vueConfigOptions = { el: '#app', data: dataOptionsObject, methods: methodsOptionObject }; var app = new Vue( vueConfigOptions ); </script>
  • 5. 데이터와 메소드의 바인딩 데이터 옵션과 메소드 옵션은 그대로 Vue 인스턴스의 데이터와 메소드가 됩니다!
  • 6. <div id="app"> <h1>웹 브라우저의 JS 콘솔을 열어 Vue 인스턴스를 확인하세요</h1> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { data1: "dummy", data2: "dummy", data3: "dummy", data4: "dummy", data5: "dummy" }, methods: { testMethod1(){ // ES6 문법 == testMethod1: function(){ return "dummy" }, testMethod2(){ return "dummy" }, testMethod3(){ return "dummy" }, testMethod4(){ return "dummy" }, testMethod5(){ return "dummy" } } }); console.log( app ); </script>
  • 7.
  • 8. 메소드의 바인딩과 화살표 함수 메소드를 화살표 함수(ES6+)로 정의할 때는 lexical this 특성에 주의해야 합니다.
  • 9. 데이터 옵션의 특징 데이터는 Vue 인스턴스에게서 감시(?!)당합니다. 데이터가 변경되면 화면을 다시 그립니다. (Render)
  • 10. <div id="app"> <h1>dataPropertyIsReactive = "{{ dataPropertyIsReactive }}"</h1> <button onclick="changeData();">변해라!</button> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { dataPropertyIsReactive: "dummy" } }); function changeData(){ const now = new Date(); app.dataPropertyIsReactive = now.toLocaleString(); }; </script>
  • 11. 계산된 속성 (Computed) 메소드 수행 결과가 캐싱됩니다. 메소드 속성처럼 정의하고 데이터 속성처럼 사용합니다.
  • 12. <div id="app"> <h1>{{ computedProperty }}</h1> <h1>{{ computedProperty }}</h1> <h1>{{ computedProperty }}</h1> <button onclick="changeData();">변해라!</button> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> const app = new Vue({ el: '#app', computed: { computedProperty(){ console.log("recompute?!"); return new Date(); } } }); function changeData(){ app.computedProperty = new Date(); }; </script>
  • 14. 그리고 계산된 속성은 메소드 내부에 데이터 옵션으로 정의된 프로퍼티를 사용하면 계산된 속성 또한 반응형이 됩니다.
  • 15. <div id="app"> <h1>{{ computedProperty }}</h1> <button onclick="changeData();">변해라!</button> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { int: 10 }, computed: { computedProperty(){ console.log("recompute?!"); return this.int + 1; } } }); function changeData(){ app.int = Math.round(Math.random()*10); }; </script>