如果不想把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這個組件 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中引入,但是這樣引入有一個問題,就是在index.html的HEADH上會多出一個空的
<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文件的簡單方法(推薦)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com