vue 引入公共css文件的简单方法(推荐)
如果不想把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>
相关推荐
background-color: blue;background-color: yellow;<input type="button" value="变蓝" @click="changeColorT
昔人已老 2020-07-19
jiedinghui 2020-10-25
Ladyseven 2020-10-22
zuncle 2020-09-28
xiaohuli 2020-09-02
葉無聞 2020-09-01
nicepainkiller 2020-08-20
AlisaClass 2020-08-09
myloveqiqi 2020-08-09
buttonChan 2020-08-02
drdrsky 2020-07-29
Ladyseven 2020-07-25
nicepainkiller 2020-07-24
AlisaClass 2020-07-19
hellowzm 2020-07-19
骆驼的自白 2020-07-18
lanzhusiyu 2020-07-19
hellowzm 2020-07-19
CSSEIKOCS 2020-07-18