yejineee
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: vue --- # 조건부 렌더링 & 리스트 렌더링 ## 🖍 조건부 렌더링 ### `v-if` `v-if` 디렉티브는 조건에 따른 블록을 렌더링한다. v-if는 디렉티브이기 때문에 하나의 엘리먼트에 추가해야 한다. 리액트 컴포넌트가 하나의 루트를 갖는것으로 이해하면될까? 하나 이상의 엘리먼트를 트랜지션하려면 보이지 않는 래퍼 역할을 하는 `<template>` 엘리먼트에 v-if를 사용할 수 있다. 리액트에서 React.Fragment와 같은 역할을 하는 것 같다. 최종 렌더링 결과에는 `<template>` 엘리먼트가 포함되지 않는다. `v-if`, `v-else`, `v-else-if`가 있다. ### `key`의 역할 vue는 엘리먼트를 처음부터 리렌더링하지 않고, 재사용하면서 엘리먼트를 최대한 효율적으로 렌더링하고자 한다. 하지만, 이것을 의도하지 않을 때도 있다. 따라서 **`key` 속성을 추가하여, 두 엘리먼트는 완전히 별개이니 재사용하지 않아야 함을 알려야 한다.** Key 값은 유니크해야 한다. ```html <template v-if="loginType === 'username'"> <label>사용자 이름</label> <input placeholder="사용자 이름을 입력하세요" key="username-input"> </template> <template v-else> <label>이메일</label> <input placeholder="이메일 주소를 입력하세요" key="email-input"> </template> ``` 여기서 `<label>` 엘리먼트는 `key` 속성이 없기 때문에, 효율적으로 재사용된다. ### `v-show` v-show 또한 마찬가지로 조건부 렌더링을 해준다. ```html <h1 v-show="ok">Hello!</h1> ``` ### v-if vs v-show - **v-if** v-if는 이벤트 리스너와 자식 컴포넌트가 완전히 제거되거나 새로 생성되도록 한다. 또한, v-if는 **lazy**하다. 처음 렌더링될때 초기 조건이 false라면 조건 블락은 렌더링되지 않는다. - **v-show** 초기 조건 여부와 관계없이 무조건 렌더링된다. 토글은 css의 display 속성을 변경시킴으로써 이루어지게 된다. - 결론 v-if는 토글하는데 비용이 크고, v-show는 초기 렌더링하는데 비용이 크다. 따라서 토글이 많이 일어나는 경우는 v-show, 토글이 자주 안일어나고 조건이 자주 안변경될 것 같으면 v-if를 사용하면 된다. ### v-if와 v-for **v-if와 v-for를 같이 사용하는것은 권장되지 않는다.** 만약 둘을 같이 사용한다면, **v-for가 더 우선순위가 높다.** ## 🖍 리스트 렌더링 ### v-for v-for을 이용해서 리스트를 렌더링하낟. `item in items` 형태로 반복된다. 두 번째 인자에 인덱스가 전달된다. ```htmlembedded= <ul id="example-2"> <li v-for="(item, index) in items"> {{ parentMessage }} - {{ index }} - {{ item.message }} </li> </ul> ``` ### v-for with object 객체를 순회해서 보여줄 수 있다. 순서는 value, key, index이다. ```htmlembedded= <ul id="v-for-object" class="demo"> <li v-for="(value, key, index) in object"> {{ value }} - {{key}} - {{index}} </li> </ul> ``` ```js const objectList = new Vue({ el: '#v-for-object', data: { object: { title: 'How to do lists in Vue', author: 'Jane Doe', publishedAt: '2016-04-10', }, }, }); ``` ### Maintaining State - **`in-place patch`** Vue가 v-for에서 렌더링된 엘리먼트의 목록을 갱신할 때, in-place patch 전략을 사용한다. 데이타의 순서가 변경되었을 때, DOM 엘리먼트를 옮기기보다는, 뷰는 엘리먼트를 적절한 위치에서 patch시키고, 해당 인덱스에서 렌더링할 내용을 반영하는지를 확인한다. 이 기본 모드가 효율적이지만, **리스트의 결과가 자식 컴포넌트 상태에 의존적이지 않고, 임시의 DOM 상태(e.g. form input values)에 의존하지 않을 때 적합하다.** => 왜❓ DOM은 개별 요소를 추적하고, 기존 엘리먼트를 재사용, 재정렬하기 위해 고유한 `key`를 각각 제공해야 한다. key는 고유한 아이디여야 하며, primitive type이어야 한다. ```html <div v-for="item in items" v-bind:key="item.id"> <!-- content --> </div> ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully