MOPCON
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    # Vue.js 3.0 與 Composition API 的變革 - Kuro Hsu {%hackmd MNcuRlXoQDak0uCmtaJKwA %} ###### tags: `MOPCON 2019` * [Vue Roadmap](https://github.com/vuejs/vue/projects/6) - 10/05 [Vue 3.0 Pre Alpha](https://github.com/vuejs/vue-next) ![更新前後,效能比對](https://i.imgur.com/gZ7XagK.png) > 參考 Reference : VueConf2019SH_Evan * 目標是更小更快 * 加強對 TypeScript 的支援 * 加強 API 的一致性 * 開放框架底層的擴充功能 * 畫面更新偵測API: Object.defineProperty => Proxy API (IE不支援,來跟舊瀏覽器說掰掰) > Virtual DOM 重構 > 增強編譯時的優化 ### Class API - 為了增強與 TypeScript 的支援 - 與現有 API 的相容性差異太大 - 瀏覽器對原生 API 的支援還不夠完整 ### Composition API - 先前叫 function-based API - **組合代替繼承** 實踐元件功能的reuse - 對 TypeScript 類型推導的支援更好 - Tree-shaking friendly, 編譯後程式碼更容易被壓縮 ### Mixins :-1: 可能造成 Namespace 衝突 :-1: 從 Mixins 引入的 options 難以追蹤來源 ![mixin](https://i.imgur.com/2y9PuT1.png) > 參考 Reference : VueConf2019SH_Evan ### HOC: Higher-order Components _大腸包小腸_ 三層以內的還算能維護,超過就很難追蹤來源 ![higher-order components](https://i.imgur.com/yRxYlYf.png) > 參考 Reference : VueConf2019SH_Evan :-1: Props來源不清晰 :-1: Props namespace confliction :-1: 多餘的元件實體造成性能浪費 ### Renderless Components ![Renderless Components](https://i.imgur.com/jqDIUSW.png) > 參考 Reference : VueConf2019SH_Evan :+1: options 來源清晰 :+1: 無 namespace 衝突問題 :-1: 多餘的元件實體造成性能浪費 ### Composition API :+1: 資料來源清晰 :+1: 無 namespace 衝突問題 :+1: 不會產生元件實體造成性能浪費 Vue 2.0 可額外安裝套件以便使用: https://github.com/vuejs/composition-api/ ### setup() - 沒有 this - 將共用邏輯放在 setup 函式 - 透過 context 參數取得原本在 this 對應的屬性 - 將需要暴露的屬性 return 出去 ### 解決 mixin - 撞名問題 > Composition API 很像是 React 的 Hooks,以及包含 React 的 Custom Hooks 的精神,讓原本重複的邏輯可以拆成很像是普通的 function,在需要時 import 進來就可以使用。 ### Demo [Github: kurotanshi/vue-composition-api-demo](https://github.com/kurotanshi/vue-composition-api-demo) ### ref() - 生成一個響應式的屬性 (如 react 的 state hook) - 透過 .value 屬性存取 ### reactive() - 意義上等同於 V2.x 的 Vue.observable() - 無須透過 .value 屬性存取 ### Lifecycle hooks - 將原本 Lifecycle hooks 透過 onXXX 的形式來對應 ### 與React Hooks對比 - 兩者同時為了處理元件複用 - Vue setup() 只會在 init 被呼叫一次 - 沒有React Hook 的Garbage Colleciton和Life Cycle問題,React Hook 開發者必須要自己優化。 [Vue RFCs 簡報](https://slides.com/hunterliu1003/vue-rfcs) [Vue社團](https://vue.tw)

    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