basic
#
Vue 初學筆記#
SPA Single Page Application用框架來實現 SPA
局部渲染頁面
網頁元件化,使用邏輯控制組件
處理 URL 和資料流
#
textThe most basic form of data binding is text interpolation using the “Mustache” syntax (double curly braces)
#
v-bindhtml 標籤屬性用 v-bind 把 資料放進去,並可省略成:
用 true/false 切換 HTML 屬性值
插入多個值運用陣列
#
v-for用於陣列迭代案 陣列可以使用第二個參數取得索引值
#
v-model表單輸入框的雙向綁定
use the v-model directive to create two-way data bindings on form input
雙向綁定: 資料會影響畫面,而畫面也會影響資料,使用者能透過表單輸入框填寫資料,如果 Vue 能即時拿到使用者產生的資料,就可以設計程式讓畫面和使用者即時互動
v-on 縮寫:@
取得 event 物件 $event
#
v-ifThe directive v-if is used to conditionally render a block. The block will only be rendered if the directive’s expression returns a truthy value.
根據表達式的的值的 truthiness 来有条件地渲染元素。在切换时元素及它的数据绑定 / 组件被销毁并重建。
元素會被忽略,根本就不在瀏覽器的 DOM tree 裡
切換頻率小的情況,使用 v-if 則無傷大雅
#
v-elseYou can use the v-else directive to indicate an “else block” for v-if:
tip
A v-else element must immediately follow a v-if or a v-else-if element - otherwise it will not be recognized.
#
v-showThe difference is that an element with v-show will always be rendered and remain in the DOM; v-show only toggles the display CSS property of the element.
the element is always rendered regardless of initial condition, with CSS-based toggling.
使用時機: 切換頻率高,資料內容也不怕別人看,流暢最重要
#
computed使用時機: 需要處理的 data,computed 裡運算之後,再拿到 template 裡使用
computed 只有在「需要更新相關畫面」時,才會被呼叫。
computed 的本質是「運算後的資料」
#
Filtersfilters 改變資料的呈現樣子,但不改變到資料
Vue 3 以棄用
#
watch監聽資料的方法
運用函式格式來定義想要監控的對象
函式名稱 = 要監控的資料名稱
handler 如果資料改變,要執行的處理程序
#
deep 深層監聽透過 deep 可以更深層的監聽
#
Lifecycle 生命週期畫面 html 被 Vue 接管到 Vue 離開
#
Lifecycle Hooks#
created當 Vue 被創建
#
mounted當 Vue 渲染好 html
#
updated#
github pagenpm run build
cd dist
git init //因為 dist 資料夾預設是被 ignore 的,因此在進入 dist 資料夾後初始化 git
git add -A
git commit -m 'deploy'
git push -f https://github.com/indexhui/vue-todolist.git master:gh-pages