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

VueJS 大型專案架構

VueJS 大型專案架構

#假的

Cain Chen

July 13, 2016
Tweet

More Decks by Cain Chen

Other Decks in Technology

Transcript

  1. VueJS च๜Օ奧 .vue 䲆礯<template> HTML 䰬粚 ݢ犥瞲ਧ౮ jade
 襑ᥝਞ蕕 jade-loader

    ֵአ mustache * 瞲㻌稞翉ਧ {{{ፗ矑蜍ڊ HTML }}} <template lang=“jade”> <div> <h1>{{ message }}</h1> <p>{{ *message }}</p> <p>{{{ messageRawHtml }}}</p> <p class="message-{{ messageId }}"></p> </div> </template> http:/ /vue-loader.vuejs.org/en/index.html
  2. VueJS च๜Օ奧 .vue 䲆礯<style> CSS 䰬粚 ݢ犥瞲ਧ傶 scss/sass
 襑ᥝਞ蕕 sass-loader

    scoped 蔭纈蝡㮆䰬ୗݝॺ አࣁ匍磪ጱزկӤ <style lang=“scss” scoped> $primary-color: #633; .component { color: $primary-color; } </style> http:/ /vue-loader.vuejs.org/en/index.html
  3. VueJS च๜Օ奧 .vue 䲆礯<script> script 䰬粚 ݢ犥瞲ਧ傶 coffee
 襑ᥝਞ蕕 coffee-loader

    <script lang=“coffee”> # Write your coffee script here. # 犋ᥝᘍ౯ Coffee Script. </script> http:/ /vue-loader.vuejs.org/en/index.html
  4. 蝚螂秇奲砺֢ mutations。 墋ฃጱ utility.js 塅ֺ。 蝡愊ضڡত玕ԧ state。 矑茐ਧ嬝 mutations 㵕֢牐

    ኧ mutation-types 玲஑మ ᥝጱ制眲ݷ圸牐 䌘蝡犚制眲ݷ圸ਧ嬝傶獢碍牧 㪔ๅ硬 state。 Vuex mutation
  5. VueJS + vue-router 獮ᒒ᪠ኧྋ॥牐 ֢ဩ蚤ݱय़໛礍य़ݶੜ吖牐 ݢ犥狶 Nested牧㮆Ո憽஑ view 䌃蚏㬵ഇො׎牐 $router

    ݢ犥ᛔਧ嬝痀௔碍独牧ݢአෝ獊ऒ牐 䰬粚Ӿݢֵአ $route ೭ڊ碍独牐 磪 hooks ݢ犥ֵአ牧አෝ矒ګ᪠ኧ窕纷牐
  6. vue-router Hooks data
 አෝ斉獈吚獮 route ጱزկ膏虻碘碻藉咳牐 activate 
 زկࣁୌ缏褩ྦྷ牧扗奲կᤩ獺ୌӬ蝱獈 route

    ԏ獮藉咳牐 deactivate
 زկࣁୌ缏褩ྦྷ牧扗奲կܨ疥ᤩ纔አ౲ᑏᴻ碻藉咳牐
  7. vue-router Hooks data, activate, deactivate ᮷஠殾蜴ࢧ Promise ౲۱珀 Promise ጱᇔկ牐

    canActivate, canDeactivate ݢ螡䢔௔蜴ࢧ Promise ౲ Boolean牐 canReuse ஠殾蜴ࢧ Boolean牐
  8. JWT + Auth0 獊ݷ傶 JSON Web Token牐 犥 PHP 傶ֺ牧ݢ犥ֵአ

    firebase/php-jwt 㬵叨ኞ牐 犋ฎ碝ጱ䩚ᥜ牐 ๅग़ JWT+auth0 with VueJS ݢ㷢ᘍ https:/ /goo.gl/gdf3H8
  9. JWT + Auth0 犥 Vuex 吚Ӿጱ actions 玲஑ Token牐 㱪ਂෝ

    store 吚Ӿ牐 疥 Token ࢧ䌃ᛗ header Authorization牐 ֵአ localStorage 氃क़㱪ਂ Token牐 ౲ֵአ Cookie 㱪ਂ牐