近期在做仿網(wǎng)易云音樂的項目堆巧,api用到GitHub上
NeteaseCloudMusicApi項目。
技術(shù)棧:Vue2.x,elementUI谍肤,Vuex啦租,Vue Router
其中遇到部分問題特記錄下:
1.elementUI中修改樣式問題
如果想要修改elementUI,可以使用全局css荒揣。并在main.js中import刷钢。這樣自定義的樣式會作用的到對應(yīng)的組件上例如
/* 自定義menu樣式 */
.el-menu-item {
height: 40px;
line-height: 40px;
margin-bottom: 3px;
}
.el-menu-item.is-active {
color: #313131;
background-color: #f6f6f7;
font-weight: bold;
font-size: 15px;
}
特別注意,class的名字一定要與elementUI的組件名一致乳附,具體原因看下組件源碼樣式class就是組件名稱内地。如果不想全局引用「吵可以在vue文件中阱缓,添加/deep/:
/deep/
.el-menu-item {
height: 40px;
line-height: 40px;
margin-bottom: 3px;
}
/deep/
.el-menu-item.is-active {
color: #313131;
background-color: #f6f6f7;
font-weight: bold;
font-size: 15px;
}
這樣就可以在vue文件更改對應(yīng)樣式。
2.基礎(chǔ)布局問題使用position:absolute
absolute和relative的區(qū)別
absoleute絕對定位的意思是說举农,它的定位不受父元素中其他元素的影響
relative相對定位荆针,就是會受到父元素中其他元素影響
其中又left,right颁糟,top航背,bottom等控制元素所在位置。
對于absolute狀況下:
left是棱貌,子控件玖媚,距離包含他的父控件的左側(cè)的位置多少。類似padding-left婚脱。
right今魔,top,bottom同上
其中障贸,如果想做動態(tài)的布局错森,元素塊隨著窗口的大小改變而改變,可以這樣用篮洁。
不設(shè)置width涩维,設(shè)置父,子塊元素的left袁波,right瓦阐,top, bottom即可锋叨。如果父級設(shè)置垄分,子元素也要設(shè)置,不然對應(yīng)效果不會顯示的娃磺。
.main {
position: absolute;
width: auto;
height: auto;
bottom: 80px;
top: 60px;
left: 0;
right: 0;
}
/* 位置absolute,搭配bottom可以標(biāo)注叫倍,此元素 位置固定偷卧,
left豺瘤,right,top听诸,bottom因該都是距離父容器左右坐求,上下多少px
對于絕對定位元素,bottom屬性設(shè)置單位高于/低于包含它的元素的底邊晌梨。
對于相對定位元素桥嗤,bottom屬性設(shè)置單位高于/低于其正常位置的元素的底邊。 */
.aside {
position: absolute;
width: 200px;
height: 100%;
left: 0;
bottom: 0;
}
.main-right {
left: 200px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: auto;
height: 100%;
.view-main {
width: 90%;
margin: 0 auto;
max-width: 1200px;
}
}
具體效果自行腦補(bǔ)仔蝌。
3.js使用if語句判斷數(shù)據(jù)類型或值是否相等時候泛领,一定注意數(shù)據(jù)類行時候相同!是否需要強(qiáng)制轉(zhuǎn)換敛惊!
ps:
會不定期的更新vue項目開發(fā)中遇到的部分坑吧渊鞋。