- 在 APP.vue 中引入外部文件時,注意路徑的大小寫問題(會警告或者報錯)
- 給元素添加
v-for = 'item in list'
后再標(biāo)簽內(nèi)添加key
可以解決復(fù)用問題殊者,在后邊循環(huán)標(biāo)簽中使用item
-
<router-link :to="{name:'xxx'}"></router-link>
(一定要加引號) - 在 Vue 中引入 Axios 時要將 Axios 添加到 Vue 原型中使用
Vue.prototype.$http=Axios
(‘http’為自定義) - 過濾器(全局)放在 Vue 實例的上邊艾栋,以防止出警告
- 動態(tài)綁定屬性時略号,一定要加
v-bind:
如:<img :src='xxx'>
<div :class='xxx'></div>
- v-bind 綁定屬性時曲聂,數(shù)組語法和對象語法可混用
對象語法:鍵====>類名亿乳、值====>布爾值 - 在各組件的輸出(
export
)中归粉,data
必須是方法 -
switch (xxx) {case 'aaa' ; bbb ; break;........}
選擇符合xxx的那一項,要記得加break
官方文檔 -
arr.splice( index , howmany , item1 , ...... , itemn)
index
:開始的索引橱鹏;howmany
:刪除多少個(可為0)膜蠢;itemn
:添加的新元素 -
@click='方法名'
不帶()時堪藐,即不帶參數(shù)時,傳入methods
中的參數(shù)是event
事件 - 子組件向父組件傳遞數(shù)據(jù)時挑围,
<div @Fn1='Fn2'></div>
礁竞,Fn1
是子組件發(fā)布的訂閱模式的函數(shù)名,Fn2
是父組件定義的方法名 -
this.$http.get(xxxxx,${this.$router.params.id})
(跳轉(zhuǎn)到該組件路由中時傳入的參數(shù)杉辙,對應(yīng)的文章) - beforeMount:生命周期鉤子模捂,在掛在開始之前調(diào)用,在渲染之前(渲染器件不被調(diào)用)奏瞬。本例中用于獲取 API 數(shù)據(jù)啊
- 在同一頁面中枫绅,兩個組件同時存在泉孩,組件 B 存在組件 A 的跳轉(zhuǎn)路由硼端,這時點擊組件 B 中路由時,路由發(fā)生改變寓搬,但是頁面不會重新渲染珍昨,這時就需要使用到監(jiān)聽器,監(jiān)聽路由的變化句喷,如:
watch : {
$router : function ( to , from ) {
this.getArticle() //路由改變時镣典,重新獲取數(shù)據(jù)
}
}
各組件間的跳轉(zhuǎn),通過路由傳入路徑唾琼、參數(shù)以達(dá)到路由不同
- 路由配置(必須引入兄春,輸出)哪個組件使用到路由就引入哪組件。輸出:
export default new Router ({
routes : [{ //定義路由
name : 'article',
path : '/topic/:id&author=:name', //跳轉(zhuǎn)路徑锡溯。動態(tài)綁定 router-link 傳來的參數(shù)
component : { //使用組件
main : Article, //跳轉(zhuǎn)到組件
slide : Slidebar
}
}]
})
在組件中使用路由時(Postlist):
<router-link :to="{ //跳轉(zhuǎn)到赶舆。。祭饭。
name : 'article', //跳轉(zhuǎn)到 name 為 article 組件
params : { //路由跳轉(zhuǎn)是傳入的參數(shù)
id : item.id, //跳轉(zhuǎn)的組件為路由中的參數(shù)與路由中path 對應(yīng)
name : item.author.loginname
}
}"></router-link>
Vue 項目在 Git 部署方法
1.更改路徑芜茵,即 config
目錄下的 index.js
文件,修改 build
(不是dev
)改為 assets PublicPath : './'
-
npm run build
生成dist
文件夾
若字體圖標(biāo)無法顯示倡蝙,打開根目錄下build
中utils.js
在控制build
樣式文件代碼中添加PublicPath : '../../'
if (options.extract){xxx, PublicPath : '../../'}
在重新npm run build
- 在
.gitignore
中忽略列表中去除/dist/