You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/v2/guide/components-edge-cases.md
+37-33Lines changed: 37 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -167,39 +167,41 @@ inject: ['getMap']
167
167
168
168
의존성 주입에 대해서 [API 문서](https://vuejs.org/v2/api/#provide-inject) 에서 더 알아보세요.
169
169
170
-
## Programmatic Event Listeners
170
+
## 프로그래밍적 이벤트 리스터
171
+
172
+
지금까지 본 `$emit`을 사용하고 `v-on` 으로 듣는 방법 외에도 Vue 인스턴스는 또다른 이벤트 인터페이스 사용 방법을 가지고 있습니다. 우리는 다음과 같이 작성할 수 있습니다:
171
173
172
174
So far, you've seen uses of `$emit`, listened to with `v-on`, but Vue instances also offer other methods in its events interface. We can:
173
175
174
-
-Listen for an event with `$on(eventName, eventHandler)`
175
-
-Listen for an event only once with `$once(eventName, eventHandler)`
176
-
-Stop listening for an event with `$off(eventName, eventHandler)`
176
+
-`$on(eventName, eventHandler)` 을 이용한 이벤트 청취
177
+
-`$once(eventName, eventHandler)` 를 이용한 단발성 이벤트 청취
178
+
-`$off(eventName, eventHandler)` 를 이용한 이벤트 청취 중단
177
179
178
-
You normally won't have to use these, but they're available for cases when you need to manually listen for events on a component instance. They can also be useful as a code organization tool. For example, you may often see this pattern for integrating a 3rd-party library:
180
+
위의 방법들은 일반적으로 사용할 일이 없지만 컴포넌트 인스턴스 안의 이벤트를 수동적으로 청취하고자 하는 경우에 사용할 수 있습니다. 또한 코드를 조직화하는 도구로써 유용하게 사용될 수 있습니다. 예를 들어, 아래와 같이 서드파티 라이브러리를 사용하는 경우가 있습니다:
179
181
180
182
```js
181
-
//Attach the datepicker to an input once
182
-
//it's mounted to the DOM.
183
+
//datepicker를 input에 한 번 연결합니다.
184
+
//DOM에 직접 연결됩니다.
183
185
mounted:function () {
184
-
//Pikaday is a 3rd-party datepicker library
186
+
//Pikaday는 서드파티 라이브러리입니다.
185
187
this.picker=newPikaday({
186
188
field:this.$refs.input,
187
189
format:'YYYY-MM-DD'
188
190
})
189
191
},
190
-
//Right before the component is destroyed,
191
-
//also destroy the datepicker.
192
+
//컴포넌트를 destroy하기 직전에
193
+
//datepicker를 destroy합니다.
192
194
beforeDestroy:function () {
193
195
this.picker.destroy()
194
196
}
195
197
```
196
198
197
-
This has two potential issues:
199
+
이는 두 가지의 잠재적 이슈를 갖습니다:
198
200
199
-
-It requires saving the `picker` to the component instance, when it's possible that only lifecycle hooks need access to it. This isn't terrible, but it could be considered clutter.
200
-
-Our setup code is kept separate from our cleanup code, making it more difficult to programmatically clean up anything we set up.
201
+
-라이프사이클 훅에서만 `picker`에 접근할 수 있는 경우, `picker` 가 컴포넌트 인스턴스 안에 저장되어야 합니다. 끔찍한 정도는 아니지만, 다소 어색하게 느껴질 수 있습니다.
202
+
-셋업을 위한 코드와 제거를 위한 코드가 분리되어 있기에 무언가를 제거하거나 설치하는데 있어 (프로그래밍적으로) 어려워집니다.
201
203
202
-
You could resolve both issues with a programmatic listener:
204
+
프로그래밍적 리스너를 이용하면 위 두 가지 이슈를 모두 해결할 수 있습니다:
203
205
204
206
```js
205
207
mounted:function () {
@@ -214,7 +216,7 @@ mounted: function () {
214
216
}
215
217
```
216
218
217
-
Using this strategy, we could even use Pikaday with several input elements, with each new instance automatically cleaning up after itself:
219
+
이러한 방법을 이용하면 우리는 Pikaday를 가양한 input 엘리먼트에 사용할 수 있으며, 각각의 새로운 인스턴스는 사용되고 난 후 자동으로, 스스로 이를 정리합니다:
218
220
219
221
```js
220
222
mounted:function () {
@@ -235,42 +237,44 @@ methods: {
235
237
}
236
238
```
237
239
238
-
See [this fiddle](https://jsfiddle.net/09jvu65m/) for the full code. Note, however, that if you find yourself having to do a lot of setup and cleanup within a single component, the best solution will usually be to create more modular components. In this case, we'd recommend creating a reusable `<input-datepicker>` component.
240
+
전체 코드를 확인하려면 [여기](https://jsfiddle.net/09jvu65m/)를 확인하세요. 만일 스스로가 단일 컴포넌트를 셋업하고 제거하는 과정을 여러 번 반복하고 있는 경우, 모듈화된 컴포넌트가 가장 좋은 솔루션일 수 있다는 사실을 기억해 두세요. 위의 경우에는 재사용 가능한 `<input-datepicker>` 컴포넌트를 만드는 것을 추천합니다.
241
+
242
+
프로그래밍적 이벤트 리스너에 대해서 더 학습하고 싶다면 API 문서의 [Events Instance Methods](https://vuejs.org/v2/api/#Instance-Methods-Events) 를 확인 해 보세요.
243
+
239
244
240
-
To learn more about programmatic listeners, check out the API for [Events Instance Methods](https://vuejs.org/v2/api/#Instance-Methods-Events).
241
245
242
-
<pclass="tip">Note that Vue's event system is different from the browser's <ahref="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget">EventTarget API</a>. Though they work similarly, <code>$emit</code>, <code>$on</code>, and <code>$off</code> are <strong>not</strong> aliases for <code>dispatchEvent</code>, <code>addEventListener</code>, and <code>removeEventListener</code>.</p>
246
+
<pclass="tip"> Vue의 이벤트 시스템은 브라우저의 <ahref="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget">EventTarget API</a>와는 다르다는 사실을 기억하세요. 비슷하게 동작하기는 하지만, <code>$emit</code>, <code>$on</code>, and <code>$off</code> 는 <code>dispatchEvent</code>, <code>addEventListener</code>, and <code>removeEventListener</code>의 축약어가 <strong>아닙니다.</strong></p>
243
247
244
-
## Circular References
248
+
## 순환 참조
245
249
246
-
### Recursive Components
250
+
### 재귀 컴포넌트
247
251
248
-
Components can recursively invoke themselves in their own template. However, they can only do so with the `name` option:
252
+
컴포넌트는 재귀적으로 템플릿 안에서 호출될 수 있습니다. 하지만 `name` 옵션을 이용해서만 호출될 수 있습니다:
249
253
250
254
```js
251
255
name:'unique-name-of-my-component'
252
256
```
253
257
254
-
When you register a component globally using `Vue.component`, the global ID is automatically set as the component's`name`option.
258
+
`Vue.component`를 이용해 컴포넌트를 전역으로 등록하는 경우, 전역 ID는 자동으로 컴포넌트의`name`옵션의 값으로 설정됩니다.
255
259
256
260
```js
257
261
Vue.component('unique-name-of-my-component', {
258
262
// ...
259
263
})
260
264
```
261
265
262
-
If you're not careful, recursive components can also lead to infinite loops:
A component like the above will result in a "max stack size exceeded" error, so make sure recursive invocation is conditional (i.e. uses a `v-if`that will eventually be `false`).
273
+
위와 같은 컴포넌트는 "max stack size exceeded(최대 스택 사이즈가 초과되었습니다)" 에러를 출력하므로, 재귀적 호출에 올바른 조건이 설정되어있는지 확인하여야 합니다. (예: `v-if`에 최종적으로 `false`가 들어가는가?)
270
274
271
-
### Circular References Between Components
275
+
### 두 컴포넌트 사이의 순환 참조
272
276
273
-
Let's say you're building a file directory tree, like in Finder or File Explorer. You might have a `tree-folder` component with this template:
277
+
Finder나 File Explorer 같은 파일 디렉토리 트리를 만드는 경우를 생각해 봅시다. 아마 아래와 같은 `tree-foler` 컴포넌트를 만들었을 것입니다:
274
278
275
279
```html
276
280
<p>
@@ -279,7 +283,7 @@ Let's say you're building a file directory tree, like in Finder or File Explorer
279
283
</p>
280
284
```
281
285
282
-
Then a `tree-folder-contents`component with this template:
286
+
그리고 `tree-folder-contents`컴포넌트는 아래와 같은 템플릿을 가지고 있을 것입니다:
283
287
284
288
```html
285
289
<ul>
@@ -290,33 +294,33 @@ Then a `tree-folder-contents` component with this template:
290
294
</ul>
291
295
```
292
296
293
-
When you look closely, you'll see that these components will actually be each other's descendent _and_ ancestor in the render tree - a paradox! When registering components globally with `Vue.component`, this paradox is resolved for you automatically. If that's you, you can stop reading here.
297
+
자세히 보면 이 컴포넌트들이 실제로는 서로의 후손이면서 조상이라는 것을 알 수 있습니다 - 패러독스죠! 만약 당신이 `Vue.component`를 이용해서 컴포넌트를 전역으로 등록하는 경우에 이 패러독스는 자연스럽게 해결됩니다. 이렇게 문제가 해결되었다면 여기까지만 읽어도 괜찮습니다.
294
298
295
-
However, if you're requiring/importing components using a __module system__, e.g. via Webpack or Browserify, you'll get an error:
299
+
하지만 만약에 **모듈 시스템**을 이용해(즉, Webpack이나 Browserify를 이용해) require 혹은 import를 시도한 경우, 아래와 같은 에러가 발생합니다:
296
300
297
301
```
298
302
Failed to mount component: template or render function not defined.
299
303
```
300
304
301
-
To explain what's happening, let's call our components A and B. The module system sees that it needs A, but first A needs B, but B needs A, but A needs B, etc. It's stuck in a loop, not knowing how to fully resolve either component without first resolving the other. To fix this, we need to give the module system a point at which it can say, "A needs B _eventually_, but there's no need to resolve B first."
305
+
무슨 일이 일어났는지를 설명하기 위해서, 우리의 컴포넌트를 A와 B라고 부르겠습니다. 모듈 시스템의 입장에서는 A가 필요한데 A는 B가 필요하고, 다시 B는 A가 필요하고, 하지만 A는 B가 필요하고, 기타 많은 것들(...)이 필요하게 됩니다. 즉, 두 컴포넌트 모두 다른 컴포넌트 하나가 정의되기 전에 정의될 수 없는 루프에 빠지는 것입니다. 이를 해결하기 위해서는 모듈 시스템에 "결과적으로 A는 B를 필요로 하게 되지만, B를 우선적으로 정의할 필요는 없다"라는 사실을 전달하여야 합니다.
302
306
303
-
In our case, let's make that point the `tree-folder`component. We know the child that creates the paradox is the `tree-folder-contents` component, so we'll wait until the `beforeCreate`lifecycle hook to register it:
307
+
본 예시에서는 `tree-folder`컴포넌트에 포인트를 만들어 봅시다. `tree-folder-component` 컴포넌트가 패러독스를 발생시키는 자식요소라는 것을 알고 있으므로, `beforeCreate`라이프사이클 훅이 호출되기를 기다렸다가 컴포넌트를 등록합니다:
0 commit comments