vue 引入公用css檔案的簡單方法(推薦),vuecss

來源:互聯網
上載者:User

vue 引入公用css檔案的簡單方法(推薦),vuecss

如果不想把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檔案的簡單方法(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.