Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Components と Vue.js

Web Components と Vue.js

v-kansai Vue.js/Nuxt.js meetup #7 で発表した10分LTです
https://vuekansai.connpass.com/event/127057/

ゆきしば

June 22, 2019
Tweet

More Decks by ゆきしば

Other Decks in Technology

Transcript

  1. Web Components と Vue.js Web Components について Web Components は、再利用可能なカスタム要素を作成し、

    ウェブアプリの中で利用するための、一連のテクノロジーです。 コードの他の部分から独立した、カプセル化された機能を使って実現します。 MDN Web docs ‒ https://developer.mozilla.org/ja/docs/Web/Web̲Components
  2. Web Components と Vue.js Web Components について Web Components は、再利用可能なカスタム要素を作成し、

    ウェブアプリの中で利用するための、一連のテクノロジーです。 コードの他の部分から独立した、カプセル化された機能を使って実現します。
  3. Web Components と Vue.js Web Components について Custom Elements HTML

    CSS JavaScript HTML Template / Shadow DOM <custom‒elem> … </custom‒elem>
  4. Web Components と Vue.js Vue.js における、ふたつのライブラリ Vue Custom Element こっちを使っています。

    公式。Web標準の「カスタムエレメントレジストリ」でコンポーネントを登録。 位置づけ的には後継なので、こちらに移行することになりそう。 IE9以降やEdgeにかんたん対応! @vue/web‒component‒wrapper https://github.com/karol‒f/vue‒custom‒element https://github.com/vuejs/vue‒web‒component‒wrapper
  5. Web Components と Vue.js Vue.js における、ふたつのライブラリ Vue Custom Element デフォルトで

    shadow DOM を使わないので、サイトのスタイルをそのまま適用できる。 もちろんshadowDOMも使える。 コンポーネントは shadow DOM として登録される。 Vue Custom Element からの移行時は、shadow DOM 前提の設計になってるか要確認。 @vue/web‒component‒wrapper https://github.com/karol‒f/vue‒custom‒element https://github.com/vuejs/vue‒web‒component‒wrapper
  6. Web Components と Vue.js Vue.js における、ふたつのライブラリ Vue Custom Element import

    vueCustomElement from ‘vue‒custom‒element’; import CustomElement from ‘customElement.vue’; Vue.use(vueCustomElement); Vue.customElement(‘v‒custom‒element’, customElement); import wrap from ‘@vue/web‒component‒wrapper’ const CustomElement = wrap(Vue, () => import(̀customElement.vuè)) window.customElements.define(‘v‒custom‒element’, CustomElement) @vue/web‒component‒wrapper
  7. Web Components と Vue.js Vue.js における、ふたつのライブラリ Vue Custom Element import

    vueCustomElement from ‘vue‒custom‒element’; import CustomElement from ‘customElement.vue’; Vue.use(vueCustomElement); Vue.customElement(‘v‒custom‒element’, customElement); import wrap from ‘@vue/web‒component‒wrapper’ const CustomElement = wrap(Vue, () => import(̀customElement.vuè)) window.customElements.define(‘v‒custom‒element’, CustomElement) @vue/web‒component‒wrapper 入力形式(Vue.js コンポーネント)と 出力形式(Custom Elements)が同じなので、 基本的にはそのまま移行できる。
  8. Web Components と Vue.js Webサイトでの利用 ‒ コンテンツのソースはシンプルなまま、JSで機能を付加したい。 ‒ jQueryで書いていたようなところで、便利に使える。 ‒

    依存関係がコンテンツ上のカスタム要素と1対1なので、管理がしやすい。 ‒ 弊社内ではここ1年くらい Vue Custom Element を使用してきた。
  9. Web Components と Vue.js Webサイトでの利用 イラストマップ上にピンを立てて、クリックしたら写真を開きたい 同時にピンを立てた場所の一覧を表示し、そこからも写真を開きたい CMSの記事内で使うので、WYSIWYGエディタ作業で項目を増減したい たとえば、こんな依頼がありました デモを用意しました!

    デモを用意しました! https://yukishiba.github.io/demo‑vue‑custom‑element/dest/ https://yukishiba.github.io/demo‑vue‑custom‑element/dest/ あとでURL共有します! あとでURL共有します! デモを用意しました! https://yukishiba.github.io/demo‑vue‑custom‑element/dest/ (あとでURL共有します!)