下面我就为大家分享一篇vue 引入公共css文件的简单方法(推荐),具有很好的参考价值,希望对大家有所帮助。
如果不想把css写在单文件组件里如这样:
<template>
<p id="app">
<p 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>
</p>
<router-view></router-view>
</p>
</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> <p id="app"></p> <!-- built files will be auto injected --> </body> </html>
3、在app.vue中引入,但是这样引入有一个问题,就是在index.html的HEADH上会多出一个空的
<template>
<p id="app">
<p 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>
</p>
<router-view></router-view>
</p>
</template>
<script>
export default {
name: 'app'
}
</script>
<style>
@import './assets/css/reset.css'; /*引入公共样式*/
</style>上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
以上就是通过vue如何引入公共css文件的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号