Lala Code

Lala 的前端大補帖,歡迎一起鑽研前端技術😊

0%

Vue Component 組件基本介紹

組件基本介紹

main.js

1
2
3
4
5
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";

createApp(App).use(router).mount("#app");

main.js 為網站主程式的進入點,Vue 的初始化操作都在此設定
只要有使用到擴充功能,都要用.use 串接到主程式


拆分組件

App.vue
JS

1
2
3
4
5
6
7
8
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
export default {
components: {
Header,
Footer,
},
};

template

1
2
3
<header />
<router-view></router-view>
<footer />

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font-family: "Microsoft JhengHei", "Heiti TC", "sans-serif";
}
img {
display: block;
}
html,
body {
width: 100%;
height: 100%;
}

@是給 VueJs 使用的,代表 src 資料夾,CSS 使用時須在前面加上波浪符~@,使用@取代../路徑,避免 bundle 的時候出錯

Header.vue
改寫成 SCSS 時須加上 lang="scss",並將 RWD @media 放進自己的 class
scoped 只限制此檔案元素的 style

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<style lang="scss" scoped>
h6 {
color: greenyellow;
font-size: 40px;
}
header {
background-color: #373c3f;
width: 100%;
height: 97px;
@media screen and (max-width: 640px) {
transition: height 0.2s;
height: 37px;
overflow: hidden;
}
> nav {
position: relative;
width: 1024px;
height: 100%;
margin: 0 auto;
@media screen and (max-width: 1044px) {
width: 100%;
}
@media screen and (max-width: 640px) {
width: 100%;
height: 232px;
}
}
}
</style>

注入全域的 CSS

main.js

1
import "@/assets/css/reset.css";

以上是我的學習筆記,希望也有幫助到你哦 😀



Hey!想學習更多前端知識嗎?

最近 Lala 開了前端課程 👉【實地掌握RWD - 12小時新手實戰班】👈
無論您是 0 基礎新手,又或是想學 RWD 的初學者,
我們將帶你從零開始,深入了解並掌握 RWD 響應式網頁設計的核心技術,快來一起看看吧 😊



🚀線上課程分享

線上課程可以加速學習的時間,省去了不少看文件的時間XD,以下是我推薦的一些課程
想學習更多關於前後端的線上課程,可以參考看看。

Hahow

Hahow 有各式各樣類型的課程,而且是無限次數觀看,對學生或上班族而言,不用擔心被時間綁住



六角學院

如果你是初學者,非常推薦六角學院哦!
剛開始轉職也是上了六角的課,非常的淺顯易懂,最重要的是,隨時還有線上的助教幫你解決問題!


Udemy

Udemy 裡的課程非常的多,品質普遍不錯,且價格都滿實惠的,CP值很高!
也是很多工程師推薦的線上課程網站。
❤️