Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Nuxt 入門
Search
Knovour
July 12, 2017
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Nuxt 入門
Knovour
July 12, 2017
More Decks by Knovour
See All by Knovour
Elm 入門
knovour
1
230
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
Six Lessons from altMBA
skipperchong
29
4.5k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
How STYLIGHT went responsive
nonsquared
100
6.3k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Music & Morning Musume
bryan
48
7.4k
The SEO Collaboration Effect
kristinabergwall1
1
590
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
The Cult of Friendly URLs
andyhume
79
7k
Transcript
(╭ ̄3 ̄)╭ὑ Nuxt入⾨門 ⸜(* ॑꒳ ॑* )⸝ ver 0.10.7
,OPWPVS 転転創意 - 前端⼯工程師 About Me
Why Nuxt ? 4434&0 ⯏ⴕ侮ざ7VF7VFSPVUFS7VFY⿻7VFNFUB 矦⻋SPVUF鏤㹁
$PEF4QMJU -JGFJTTIPSU 8FCQBDLJTIBSE
tientien.tw 歊歊詫卓
( ͡ ° ͜ ʖ ͡ °) 相關指令
vue init nuxt/starter <project-name> 㸞酤 npm install --save nuxt yarn
add nuxt 透過 vue-cli ⾃自主安裝
㛂遤 "scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt
start", "generate": "nuxt generate", // ⽣生成靜態⾴頁⾯面 "analyze": "nuxt build --analyze" // ⽣生成 bundle 解析圖 }, "config": { "nuxt": { "host": "0.0.0.0", "port": 9000 } }, package.json
Analyze
d(`・∀・)b 專案結構
㼠呪穡圓 BTTFUT佞㕬晚$44瘞 DPNQPOFOUT穉⟝ MBZPVUTSPVUFⴗ䳖儘♶剚隶⹛涸鿈ⴕ NJEEMFXBSF
QBHFT⚺銴갤⟃须俲㣰穡圓莅墂そ⢵⼦ⴕSPVUF QMVHJOT佞겙㢫鯺Ⰵ涸KT TUBUJDSPCPUUYU瘞ꬆ䢀暟⟝ TUPSF7VFY OVYUDPOHKT import Header from '~components/Header'
<template> <div> <nuxt/> <!--pages 進入點--> </div> </template> Layout EFGBVMUWVF
Layout FSSPSWVF <template> <div class="container"> <h1 v-if="error.statusCode === 404">Page not
found</h1> <h1 v-else>An error occurred</h1> <nuxt-link to="/">Home page</nuxt-link> </div> </template> <script> export default { props: ['error'], // statusCode & message } </script>
Pages pages/ --| _slug/ -----| comments.vue # /:slug/comments -----| index.vue
# /:slug --| users/ -----| _id.vue # /users/:id -----| index.vue # /users --| users.vue --| index.vue # / 把它當成 users 額外專屬的 layout,透過 nuxt-child 進入
Store import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex)
export default new Vuex.Store({ // Do Something }) JOEFYKT 有這個檔案,Nuxt 才會把 Vuex 打包
nuxt.config.js 〫䌢欽涸 module.exports = { srcDir: '', // 指定專案下的資料夾為 src(預設為專案⽬目錄)
env: {}, // 直接設定 process.env.XXX head: {}, // 預設 meta、link、script 等 css: [], // Global CSS loading: {}, // ⾴頁⾯面切換載入時的 progress bar plugins: [], // 額外載入的 js build: {}, // 額外的 webpack 設定 router: {} // 客制 route, transition: ‘', // 指定⾴頁⾯面切換特效 cache: '', dev: true, generate: {}, }
Plugins 佞겙㢫涸IFMQFST 鷴麕DPOH겙㢫鯺Ⰵ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-1', 'auto'); ga('send', 'pageview'); plugins: [ { src: '~plugins/GA', ssr: false } ] plugins/GA.js nuxt.config.js
(´・ω・`) API 結構
"1*穡圓 export default { asyncData (context) { return {}; //
內容將會被併入 data }, fetch (context) { return Promise; // ⾴頁⾯面切換 / SSR 前會呼叫 }, head () { // vue-meta }, layout: 'default', middleware: '', scrollToTop: true, transition: '', // ⾴頁⾯面切換特效 validate (context) { // 判斷⾴頁⾯面是否正確 } }
DPOUFYU JT$MJFOUJT4FSWFSJT%FW SPVUFWVFSPVUFS TUPSF7VFY FOW
QBSBNTRVFSZ SFRSFT SFEJSFDU FSSPSTIPXMBZPVUFSSPSWVF
( ×ω× ) 幾個⼩小坑
Vue-meta /VYU涸7VFNFUB晝劥捀剤㓂ꅾCVH @@EBOHFSPVTMZ%JTBCMF4BOJUJ[FSTDBVTJOHFSSPST ZBSO酤倞晝7VFNFUB䖕剚䪾莍涸佞♧⟨㖈OPEF@NPEVMFTOVYU酭鎹䖤ⵅ䱈 欽OQN剚湬䱺《➿
⾃自定義 route router: { extendRoutes (routes) { routes.push({ name: 'register',
path: '/register', component: path.resolve(__dirname, 'src/pages/user-entry') }, { name: 'login', path: '/login', component: path.resolve(__dirname, 'src/pages/user-entry') }) } } nuxt.config.js
_(┐「ε:)_ 相關資源
0DJBM4JUF 湱ꡠ须彂 /VYU&YBNQMFT /VYU$PNNVOJUZ /VYU$PNNVOJUZNPEVMFT
謝謝