VueJS Basics - TheOpenCloudEngine/uEngine-cloud GitHub Wiki

VueJS μ‚¬μš©λ²•μ„ κ°„λ‹¨νžˆ ν•™μŠ΅ν•œλ‹€.
VueJS λŠ” μš°λ¦¬λ‚˜λΌμ— μƒνƒœκ³„κ°€ 잘 κ΅¬μ„±λ˜μ–΄ 있고, ν•œκΈ€ λ¬Έμ„œλ‘œ 된 guide 도 잘 λ˜μ–΄μžˆλ‹€.
μ—¬κΈ°μ—μ„œλŠ” κ°„λ‹¨ν•œ μ‚¬μš©λ²•μ„ 읡히고, μžμ„Έν•œ ν•™μŠ΅μ€ guide λ¬Έμ„œ μ—μ„œ μ°Έμ‘° ν•˜κΈ°λ°”λž€λ‹€.

VueJS Basics

μ—¬κΈ°μ„œ μ‚¬μš©ν•œ μ˜ˆμ œλ“€μ„ 직접 html둜 λ§Œλ“€μ–΄μ„œ μž‘λ™ν•˜λŠ”κ²ƒμ„ μΆ”μ²œν•¨

VueJS λŠ” java 의 class 라고 μƒκ°ν•˜λ©΄ λœλ‹€.
class λŠ” member field 와 operation 둜 ꡬ성이 λ˜λŠ”λ°, VueJS λŠ” 여기에 face κ°€ μΆ”κ°€λ˜μ—ˆλ‹€.
face λŠ” template , 즉 μœ„μ˜ μ˜ˆμ œμ—μ„œ <div>에 ν•΄λ‹Ήν•˜λŠ” μ˜μ—­μ΄κ³ ,
member field λŠ” var app = λΆ€λΆ„μœΌλ‘œ λ³Ό μˆ˜μžˆλ‹€.
operation 은 setInterval() 처럼 μ‚¬μš©ν•œ 뢀뢄이닀.

Component 의 κ°œλ…μ€ 남이 λ§Œλ“€μ–΄ 놓은 것을 μ–ΈκΈ‰λ§ŒμœΌλ‘œ μ‚¬μš©ν•  수 μžˆλ‹€λŠ” μ˜λ―Έμ΄λ‹€.
μƒνƒœκ³„κ°€ 잘 ꡬ성이 λ˜μ–΄ μˆ˜λ§Žμ€ Vuejs κ°œλ°œμžλ“€μ΄ λ§Žμ€ μ»΄ν¬λ„ŒνŠΈλ“€μ„ λ§Œλ“€μ–΄ λ†“μ•˜λ‹€.
μš°λ¦¬λŠ” 이것을 μ•„λž˜μ²˜λŸΌ μ„ μ–Έλ§Œ ν•˜μ—¬ μ‚¬μš© ν•  수 μžˆλ‹€.

<script src="https://unpkg.com/[email protected]"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/vue-material.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<md-avatar> , <md-speed-dial> 같은 custom tag λ₯Ό μ‚¬μš©ν•˜μ—¬ μ–ΈκΈ‰λ§Œ ν•˜μ—¬ μ‚¬μš©ν•˜μ˜€λ‹€.
이것이 μ˜λ―Έν•˜λŠ” λ°”λŠ” λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€λ₯Ό λ§Œλ“œλŠ” νŒ€μ€ μ‚¬μš©ν•˜λ €λŠ” tag 만 λ§Œλ“€μ–΄μ„œ 관리λ₯Ό ν•˜κ³ ,
ν•©μ³μ„œ UIλ₯Ό λ§Œλ“œλŠ” νŒ€μ€ tag λ₯Ό μ‚¬μš©ν•˜μ—¬ μΌκ΄€λœ UI ꡬ성을 ν•  μˆ˜μžˆλŠ” μž₯점이 μžˆλ‹€.
μ—¬κΈ° μ˜ˆμ œμ—μ„œλŠ” vuematerial λ₯Ό μ‚¬μš©ν•˜μ˜€μ§€λ§Œ 계속 더 쒋은 component 듀이 λ‚˜μ˜€κ³  μžˆλ‹€.

μ°Έκ³  vuematerial site : https://vuematerial.io/getting-started
μ°Έκ³  component μžμ„Έν•œ μ„€λͺ… : http://www.metaworks4.io/

예제 script에 보면
Vue.component('demo-grid',{}) λŠ” demo-grid λΌλŠ” custom componentλ₯Ό λ§Œλ“  것이닀.
template 은 얼꡴이닀. idκ°€ grid-template μ΄λΌλŠ” 뢀뢄을 κ°€μ Έμ™€μ„œ μžκΈ°κ°€ μ–΄λ–»κ²Œ 생겼닀고 μ•Œλ €μ€€λ‹€.
props 뢀뢄이 μžˆλ‹€. 이 뢀뢄은 java 의 public field 라고 μƒκ°ν•˜λ©΄ λœλ‹€.
μ™ΈλΆ€μ—μ„œ 값을 μ…‹νŒ…ν•˜μ—¬ λ°€μ–΄ λ„£μ„μˆ˜κ°€ μžˆλ‹€.
data 뢀뢄은 java 둜 치면 private field 이닀. (λ‚΄λΆ€μ—μ„œλ§Œ μ“Έ 것이닀.)

<demo-grid
       :data="gridData"
       :columns="gridColumns"
       :filter-key="searchQuery">
</demo-grid>

μ—¬κΈ°μ„œ vuejs λ₯Ό μ‚¬μš©ν• λ•Œ ν•„μˆ˜μ μœΌλ‘œ μ‚¬μš©ν•˜λŠ” syntax λ₯Ό κ°„λ‹¨νžˆ μ„€λͺ…ν•˜κ² λ‹€.
MVVM 쀑에 angularjsλ‚˜ angular2+ λ₯Ό μ‚¬μš©ν•˜μ‹œλ©΄ html μƒμ—μ„œ λ³€μˆ˜λ₯Ό λ§€ν•‘ν•˜κ³ ,
if λ¬Έμ΄λ‚˜ for 문을 μ‚¬μš©ν•˜μ‹€λ•Œ, ng-model, ng-if(angularjs),
ngModel, *ngIf(angular2+) 등을 μ‚¬μš©ν•΄ λ³Έ κ²½ν—˜μ΄ μžˆμœΌμ‹€ 것이라 μƒκ°ν•œλ‹€.
angular μ—μ„œ ng λΌλŠ” prefixλ₯Ό μ‚¬μš©ν•˜μ˜€λ‹€λ©΄, vuejsμ—μ„œλŠ” v-λ₯Ό μ‚¬μš©ν•œλ‹€.
v-bind,v-on,v-for,v-if,v-model λ“± λ‹€μ–‘ν•˜κ²Œ μžˆλŠ”λ°
μ΄μ€‘μ—μ„œ v-bind,v-on λŠ” Shorthands λ₯Ό μ‚¬μš©ν•œλ‹€.

<!-- full syntax -->
<a v-bind:href="url"> ... </a>
<!-- shorthand -->
<a :href="url"> ... </a>
<!-- full syntax -->
<a v-on:click="doSomething"> ... </a>
<!-- shorthand -->
<a @click="doSomething"> ... </a>

μœ„μ˜ demo-grid μ—μ„œ :data="gridData" 뢀뢄은 v-bind λ₯Ό μ‚¬μš©ν•˜μ—¬
gridData λΌλŠ” μ™ΈλΆ€ data λ₯Ό eval ν•˜μ—¬ props 의 data 에 값을 μ£Όμž…(bind) μ‹œν‚¨ 것이닀.
λ§Œμ•½ : 이 없이 data="gridData" 라고만 μ‚¬μš©ν•˜μ˜€λ‹€λ©΄, gridData λΌκ³ ν•˜λŠ”
string λ¬Έμžμ—΄μ„ data 에 λ„£κ² λ‹€λŠ” μ˜λ―Έμ΄λ‹€.

⚠️ **GitHub.com Fallback** ⚠️