vue 引入公共css文件的簡(jiǎn)單方法(推薦)
如果不想把css寫在單文件組件里如這樣:
<template> <div id="app"> <div class='nav-box'> <ul class='nav'> <li> <a href="#/" rel="external nofollow" rel="external nofollow" >home</a> </li> <li> <a href="#/odocument" rel="external nofollow" rel="external nofollow" >document</a> </li> <li> <a href="#/about" rel="external nofollow" rel="external nofollow" >about</a> </li> </ul> </div> <router-view></router-view> </div> </template> <script> export default { name: 'app' } </script> <style> #app{ text-align:center; color:#2c3e50; margin-top:60px; } </style>
可以將css樣式寫在外部,再通過下面三種方法中的一種引入:
1、在入口js文件main.js中引入,一些公共的樣式文件,可以在這里引入。
import Vue from 'vue' import App from './App' // 引入App這個(gè)組件 import router from './router' /* 引入路由配置 */ import axios from 'axios' import '@/assets/css/reset.css'/*引入公共樣式*/
2、在index.html中引入
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>y</title> <link rel="stylesheet" type="text/css" href="src/assets/css/reset.css" rel="external nofollow" >/*引入公共樣式*/ </head> <body> <div id="app"></div> <!-- built files will be auto injected --> </body> </html>
3、在app.vue中引入,但是這樣引入有一個(gè)問題,就是在index.html的HEADH上會(huì)多出一個(gè)空的
<template> <div id="app"> <div class='nav-box'> <ul class='nav'> <li> <a href="#/" rel="external nofollow" rel="external nofollow" >home</a> </li> <li> <a href="#/odocument" rel="external nofollow" rel="external nofollow" >document</a> </li> <li> <a href="#/about" rel="external nofollow" rel="external nofollow" >about</a> </li> </ul> </div> <router-view></router-view> </div> </template> <script> export default { name: 'app' } </script> <style> @import './assets/css/reset.css'; /*引入公共樣式*/ </style>
以上這篇vue 引入公共css文件的簡(jiǎn)單方法(推薦)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)列表滾動(dòng)的過渡動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)列表滾動(dòng)的過渡動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06Vue中的methods、computed計(jì)算屬性和watch監(jiān)聽屬性的使用和區(qū)別解析
這篇文章主要介紹了Vue中的methods、computed計(jì)算屬性和watch監(jiān)聽屬性的使用和區(qū)別,本文通過示例代碼給大家介紹的非常詳細(xì)對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01el-input限制輸入正整數(shù)的兩種實(shí)現(xiàn)方式
el-input框是Element UI庫(kù)中的一個(gè)輸入框組件,用于接收用戶的輸入,這篇文章主要介紹了el-input限制輸入正整數(shù),需要的朋友可以參考下2024-02-02vue使用keep-alive進(jìn)行組件緩存方法詳解(組件不緩存問題解決)
keep-alive包裹動(dòng)態(tài)組件時(shí),會(huì)緩存不活動(dòng)的組件實(shí)例,而不是銷毀它們,下面這篇文章主要給大家介紹了關(guān)于vue使用keep-alive進(jìn)行組件緩存方法(組件不緩存問題解決)的相關(guān)資料,需要的朋友可以參考下2022-09-09vue子組件封裝彈框只能執(zhí)行一次的mounted問題及解決
這篇文章主要介紹了vue子組件封裝彈框只能執(zhí)行一次的mounted問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03