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

第一次用 Vue.js 就愛上 [改]

第一次用 Vue.js 就愛上 [改]

重新介紹 Vue.js 的特性,以及在 2.0 即將帶來的變革。
video link: https://youtu.be/jXdZlbH_ut8

2016/06/23 @ 五倍紅寶石

Kuro Hsu

June 23, 2016
Tweet

More Decks by Kuro Hsu

Other Decks in Technology

Transcript

  1. Agenda • Vue.js च๜Օ奧 • ই֜疥 Vue ے獈䌕礯 • Vue

    زկ膏ኞ޸蝰๗ • Vue 膏虻碘翉ਧ • Class 膏䰬ୗ • Ԫկ蒂ቘ • 窼獈 Vue زկ • 樄咳ૡٍ膏虻რ
  2. Vue.js • 墋㻌斕ᰁጱ JS ໛礍牧犖胼膏ٌ犢獮ᒒ໛礍/獢ୗ䓚وአ牐 • ݝ襑䌕ဳࣁ view 䍅羷现ٌ䌘䛑ጱ虋玕牐 •

    ྯ㮆奲կդ蔭加缏ጱ㻌ز牧磪ݱᛔጱ view 现虻碘螵蜉牐 • 虻碘翉ਧጱ粬௔牧奲կ膏奲կԏ樌毆戔㻌ݻ翉ਧ牧虻碘窕ๅ ਻ฃᤩഩൎ牧䁆ᤈ硳ሲ犖ๅঅ牐 • 磧螕ݳ樄咳㻌殷䛑አ纷ୗ (SPA, Single Page Application)
  3. 蝚螂 vue-cli ୌᗝ碝䌕礯 $ npm install -g vue-cli $ vue

    init webpack-simple [project name] $ cd [project name] $ npm install $ npm run dev
  4. • init • created • beforeCompile • compiled • ready

    lifecycle hooks • attached • detached • beforeDestroy • destroyed
  5. • init • created • beforeCompile • compiled • ready

    • attached • detached lifecycle hooks in Vue 2.0 • beforeDestroy • destroyed • beforeMount • mounted • beforeUpdate • updated • activated • deactivated ref: https://github.com/vuejs/vue/issues/2873#upgrade-tips
  6. • Vue 䟖አ mustache 承ဩ֢傶 template 牧
 疥独ᗝ獈 {{ }}

    ܨݢ牐 <span>Message: {{ msg }}</span> 㻌稞翉ਧ: {{* msg }} HTML ჉礕: {{{ raw_html }}} HTML 痀௔: <div id="item-{{ id }}"></div>
  7. • {{ var a = 1 }} • {{ if

    (ok) { return message } }} 犥ӥฎ犋ݳဩጱ螀ᓒୗ物 犥螀ᓒୗ֢傶虻碘㬵რ • {{ number + 1 }} • {{ ok ? 'YES' : 'NO' }} • {{ msg.split('').reverse().join('') }} ইຎᥝ氥纈ጱ虻碘襑ᥝ斃蕦褾螀ᓒ牧ݢ犥Իኧ computed 蒂ቘ牐
  8. 螂筪瑊 filter • Vue.js 犖൉׀ԧ螂筪 {{ }} 蔭螈ୗ蜍ڊ虻碘ጱۑ胼牧
 蝚螂̿ |

    ̀Ԁ蝫蔭纈牧犖ݢӞ稞Ԁ蝫ग़圵 filter牧ᥝੜஞ殼ଧ 㺔氂牐 • {{ 'abc' | capitalize }}
 ==> Abc • {{ 'abc' | uppercase }}
 ==> ABC • {{ 123456 | currency }}
 ==> $123,456.00
  9. v-if 膏 v-show • v-if 膏 v-show 磧य़ጱ癩獨ࣁෝ䌘 DOM ጱ砺֢牧v-if

    䨝狅 ᆙ礿կ究ਧฎ玽疥زկ჉礕ᛗ翕殷Ӥ牧㪔究ਧԪկ膏虻碘 ጱ緳肯ฎ玽ᥝ翉ਧᛗزկ౲ፗ矑衴䵼扗زկ牐 • v-show 㳷ฎ஠ਧ䨝叨ڊزկ牧֕犥礿կ㬵獥矦 CSS (style) ጱ氥纈膏玽牐 • 舙礿կ硬虋毱耆牧አ v-show 㬵獥矦斃螕ݳ牐
  10. ᆿ膏ৼ • 䛑蝚螂 prop 痀௔牧疥ᆿ䍅虻碘㯽螏妔ৼ奲կ牧
 ᘒ犋ฎፗ矑ኧৼ奲կፗ矑୚አᆿ䍅虻碘牐 • ৼ奲կݢ犥蝚螂 this.$parent 㬵ਂ玲犢ጱᆿ䍅奲կ牐


    ইຎᥝፗ矑玲஑礬䋿誢ጱ扖牧㳷ݢ蝚螂 this.$root 㬵ਂ玲牐 • ᆿᕟկ㳷ฎ蝚螂 this.$children 蝡㮆౮㹓 (檋ڜ)牧㬵ਂ玲犢 ጱৼ奲կ牐֕ฎᥝဳ఺ this.$children ጱ殼ଧ䨝ݑک v-if ጱ୽段牧ୌ捍ض犥 v-ref 妔ৼ奲կ戔ਧ獨ݷ犥嘦狒犋ݑ奲կ ጱ殼ଧ୽段牐
  11. ᆿৼԪկ㯽螏 • 蝚螂 $on() 㬵緳肯Ԫկ牐 • ֵአ $emit() ࣁਙӤᶎ藉咳Ԫկ牐 •

    ֵአ $dispatch() ݻӤ㯽螏Ԫկ牧Ԫկ䨝窂茐ᆿ䍅ݻӤٛု • ֵአ $broadcast() 皞砮Ԫկ牧Ԫկ䨝ݻӥ㯽螏ᕳಅ磪ጱ盅 դ奲կ牐 • ᥝဳ఺ጱฎ牧膏 DOM Event 犋ݶ牧ԪկࣁݻӤٛုጱ螂纷 Ӿ牧ᒫӞ稞䁆ᤈ callback ጱ碻狡䨝ᛔ㵕؊ྊݻӤٛု牧ᴻ覍 ࣁ callback function 愊ᶎ return true牐
  12. slot • 觊犲 angular ጱ transclusion牐 • 㷢ᘍ W3C web-components

    ጱ slot 憒塅秂伛㬵䋿 ֢牐 • slot ጱ獉਻ฎࣁ̿ᆿ奲կ̀ጱ֢አऒ獉蝱ᤈ翥捌牐
  13. 蝚螂 vue-cli ୌᗝ碝䌕礯 $ npm install -g vue-cli $ vue

    init webpack-simple [project name] $ cd [project name] $ npm install $ npm run dev
  14. Next,… Vue 2.0 ! • ֢ᘏ蔭纈毆懯 犊์Ӿෲ 咳૲牦 • Vue

    1.0 य़蟂獤ጱ API 緡ݢ窂አ • 硬ԧՋ讕牫
 https://github.com/vuejs/vue/issues/2873