vuex-help
Version:
a utilies library reduce boilerplate for vuex
547 lines (254 loc) • 23.8 kB
HTML
<html lang="kr" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vuex가 무엇인가요? · Vuex</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-vuejs/vue.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="getting-started.html" />
<link rel="prev" href="installation.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=vuejs" id="_carbonads_js"></script>
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" >
<a target="_blank" href="https://github.com/vuejs/vuex/tree/1.0/docs">
1.0 버전 문서를 보려면?
</a>
</li>
<li class="chapter " data-level="1.3" >
<a target="_blank" href="https://github.com/vuejs/vuex/releases">
릴리즈 노트
</a>
</li>
<li class="chapter " data-level="1.4" data-path="installation.html">
<a href="installation.html">
설치
</a>
</li>
<li class="chapter active" data-level="1.5" data-path="intro.html">
<a href="intro.html">
Vuex가 무엇인가요?
</a>
</li>
<li class="chapter " data-level="1.6" data-path="getting-started.html">
<a href="getting-started.html">
시작하기
</a>
</li>
<li class="chapter " data-level="1.7" >
<span>
핵심 컨셉
</span>
<ul class="articles">
<li class="chapter " data-level="1.7.1" data-path="state.html">
<a href="state.html">
상태
</a>
</li>
<li class="chapter " data-level="1.7.2" data-path="getters.html">
<a href="getters.html">
Getters
</a>
</li>
<li class="chapter " data-level="1.7.3" data-path="mutations.html">
<a href="mutations.html">
변이
</a>
</li>
<li class="chapter " data-level="1.7.4" data-path="actions.html">
<a href="actions.html">
액션
</a>
</li>
<li class="chapter " data-level="1.7.5" data-path="modules.html">
<a href="modules.html">
모듈
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.8" data-path="structure.html">
<a href="structure.html">
애플리케이션 구조
</a>
</li>
<li class="chapter " data-level="1.9" data-path="plugins.html">
<a href="plugins.html">
플러그인
</a>
</li>
<li class="chapter " data-level="1.10" data-path="strict.html">
<a href="strict.html">
Strict 모드
</a>
</li>
<li class="chapter " data-level="1.11" data-path="forms.html">
<a href="forms.html">
폼 핸들링
</a>
</li>
<li class="chapter " data-level="1.12" data-path="testing.html">
<a href="testing.html">
테스팅
</a>
</li>
<li class="chapter " data-level="1.13" data-path="hot-reload.html">
<a href="hot-reload.html">
핫 리로딩
</a>
</li>
<li class="chapter " data-level="1.14" data-path="api.html">
<a href="api.html">
API 레퍼런스
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >Vuex가 무엇인가요?</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="vuex가-무엇인가요">Vuex가 무엇인가요?</h1>
<p>Vuex는 Vue.js 애플리케이션에 대한 <strong>상태 관리 패턴 + 라이브러리</strong> 입니다. 애플리케이션의 모든 컴포넌트에 대한 중앙 집중식 저장소 역할을 하며 예측 가능한 방식으로 상태를 변경할 수 있습니다. 또한 Vue의 공식 <a href="https://github.com/vuejs/vue-devtools" target="_blank">devtools 확장 프로그램</a>과 통합되어 설정 시간이 필요 없는 디버깅 및 상태 스냅 샷 내보내기/가져오기와 같은 고급 기능을 제공합니다.</p>
<h3 id="상태-관리-패턴이란-무엇인가요">"상태 관리 패턴"이란 무엇인가요?</h3>
<p>간단한 Vue 카운터 앱부터 시작 해보겠습니다.</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
<span class="token comment" spellcheck="true">// 상태</span>
data <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token punctuation">{</span>
count<span class="token punctuation">:</span> <span class="token number">0</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token comment" spellcheck="true">// 뷰</span>
template<span class="token punctuation">:</span> <span class="token template-string"><span class="token string">`
<div>{{ count }}</div>
`</span></span><span class="token punctuation">,</span>
<span class="token comment" spellcheck="true">// 액션</span>
methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
increment <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>count<span class="token operator">++</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<p>다음과 같은 기능을 가진 앱입니다.</p>
<ul>
<li><strong>상태</strong> 는 앱을 작동하는 원본 소스 입니다.</li>
<li><strong>뷰</strong> 는 <strong>상태의</strong> 선언적 매핑입니다.</li>
<li><strong>액션</strong> 은 <strong>뷰</strong> 에서 사용자 입력에 대해 반응적으로 상태를 바꾸는 방법입니다.</li>
</ul>
<p>이것은 "단방향 데이터 흐름" 개념의 매우 단순한 도표입니다.</p>
<p style="text-align: center; margin: 2em">
<img style="width:100%;max-width:450px;" src="images/flow.png">
</p>
<p>그러나 <strong>공통의 상태를 공유하는 여러 컴포넌트</strong> 가 있는 경우 단순함이 빠르게 저하됩니다.</p>
<ul>
<li>여러 뷰는 같은 상태에 의존합니다.</li>
<li>서로 다른 뷰의 작업은 동일한 상태를 반영해야 할 수 있습니다.</li>
</ul>
<p>첫번째 문제의 경우, 지나치게 중첩된 컴포넌트는 통과하는 prop는 장황할 수 있으며 형제 컴포넌트에서는 작동하지 않습니다. 두번째 문제의 경우 직접 부모/자식 인스턴스를 참조하거나 이벤트를 통해 상태의 여러 복사본을 변경 및 동기화 하려는 등의 해결 방법을 사용해야 합니다. 이러한 패턴은 모두 부서지기 쉽고 유지보수가 불가능한 코드로 빠르게 변경됩니다.</p>
<p>그렇다면 컴포넌트에서 공유된 상태를 추출하고 이를 전역 싱글톤으로 관리해야 합니다. 이를 통해 우리의 컴포넌트 트리는 커다란 "뷰"가 되며 모든 컴포넌트는 트리에 상관없이 상태에 액세스하거나 동작을 트리거 할 수 있습니다!</p>
<p>또한 상태 관리 및 특정 규칙 적용과 관련된 개념을 정의하고 분리함으로써 코드의 구조와 유지 관리 기능을 향상시킵니다.</p>
<p>이는 <a href="https://facebook.github.io/flux/docs/overview.html" target="_blank">Flux</a>, <a href="http://redux.js.org/" target="_blank">Redux</a>, <a href="https://guide.elm-lang.org/architecture/" target="_blank">The Elm Architecture</a>에서 영감을 받은 Vuex의 기본 아이디어 입니다. 다른 패턴과 달리 Vuex는 Vue.js가 효율적인 업데이트를 위해 세분화된 반응 시스템을 활용하도록 특별히 고안된 라이브러리입니다.</p>
<p><img src="images/vuex.png" alt="vuex"></p>
<h3 id="언제-사용해야-하나요">언제 사용해야 하나요?</h3>
<p>Vuex는 공유된 상태 관리를 처리하는 데 유용하지만, 개념에 대한 이해와 시작하는 비용도 함께 듭니다. 그것은 단기간과 장기간 생산성 간의 기회비용이 있습니다.</p>
<p>대규모 SPA를 구축하지 않고 Vuex로 바로 뛰어 들었다면, 시간이 오래 걸리고 힘든일일 것입니다. 이것은 일반 적인 일입니다. 앱이 단순하다면 Vuex없이는 괜찮을 것입니다. 간단한 <a href="https://kr.vuejs.org/v2/guide/components.html#비-부모-자식간-통신" target="_blank">글로벌 이벤트 버스</a>만 있으면됩니다. 그러나 중대형 규모의 SPA를 구축하는 경우 Vue컴포넌트 외부의 상태를 보다 잘 처리할 수 있는 방법을 생각하게 될 가능성이 있으며 Vuex는 자연스럽게 선택할 수 있는 단계가 될 것입니다. Redux의 저자인 Dan Abramov의 좋은 인용이 있습니다.</p>
<blockquote>
<p>Flux 라이브러리는 안경과 같습니다. 필요할 때 알아볼 수 있습니다.</p>
</blockquote>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
<script src="//m.servedby-buysellads.com/monetization.js" type="text/javascript"></script>
<div class="bsa-cpc"></div>
<script>
(function(){
if(typeof _bsa !== 'undefined' && _bsa) {
_bsa.init('default', 'CKYD62QM', 'placement:vuejsorg', {
target: '.bsa-cpc',
align: 'horizontal',
disable_css: 'true'
});
}
})();
</script>
</div>
<a href="installation.html" class="navigation navigation-prev " aria-label="Previous page: 설치">
<i class="fa fa-angle-left"></i>
</a>
<a href="getting-started.html" class="navigation navigation-next " aria-label="Next page: 시작하기">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Vuex가 무엇인가요?","level":"1.5","depth":1,"next":{"title":"시작하기","level":"1.6","depth":1,"path":"getting-started.md","ref":"getting-started.md","articles":[]},"previous":{"title":"설치","level":"1.4","depth":1,"path":"installation.md","ref":"installation.md","articles":[]},"dir":"ltr"},"config":{"plugins":["edit-link","prism","-highlight","github","-highlight","github"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{},"github":{"url":"https://github.com/vuejs/vuex/"},"livereload":{},"search":{},"theme-vuejs":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/vuejs/vuex/tree/dev/docs"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Vuex","language":"kr","links":{"sharing":{"facebook":false,"twitter":false}},"gitbook":"2.x.x"},"file":{"path":"intro.md","mtime":"2018-02-17T07:20:49.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-03-02T20:43:43.208Z"},"basePath":".","book":{"language":"kr"}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
</body>
</html>