最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue3中如何使用SCSS編寫樣式

 更新時間:2023年12月18日 09:56:14   作者:Python私教  
在Vue模板中啟用這些表現(xiàn)力庫插件的最簡單方法是在初始化項目時安裝它們,或使用 npm install(或 yarn add)安裝包,這篇文章主要介紹了Vue3中如何使用SCSS編寫樣式,需要的朋友可以參考下

概述

When using Vue components, the Vite compiler allows you to use almost any frontend templating language style. The easiest way to enable these expressive library plugins in your Vue templates is to install them when you initialize your project, or by using npm install (or yarn add) for the package.

使用 Vue 組件時,Vite 編譯器允許您使用幾乎任何前端模板語言風(fēng)格。在 Vue 模板中啟用這些表現(xiàn)力庫插件的最簡單方法是在初始化項目時安裝它們,或使用 npm install(或 yarn add)安裝包。

When using the style tag inside of a Vue component, you can specify a language using the lang attribute, provided that you have installed that specific language plugin.

在 Vue 組件中使用樣式標(biāo)簽時,只要安裝了特定的語言插件,就可以使用 lang 屬性指定語言。

For example, if you chose to install the Stylus preprocessor, first you need to install the stylus package in your project as a dependency by performing the following command:

例如,如果您選擇安裝 Stylus 預(yù)處理器,首先需要執(zhí)行以下命令將 stylus 軟件包作為依賴關(guān)系安裝到項目中:

npm add -D stylus
#OR
yarn add -d stylus

Then, you can add the lang=“stylus” attribute to the style tag to begin using Stylus:

然后,就可以在樣式標(biāo)簽中添加 lang=“stylus” 屬性,開始使用 Stylus:

<style lang="stylus">
ul
  color: #2c3e50;
  > h2
  color: #22cc33;
</style>

Another benefit of using Vue is scoping the style with the scoped attribute. This is a useful way to create isolated and component-specific CSS stylings. It also overrides any other CSS global rules, according to the CSS rule of specificity.

使用 Vue 的另一個好處是使用 scoped 屬性對樣式進(jìn)行定義。這是一種有用的方法,可用于創(chuàng)建孤立的、特定于組件的 CSS 樣式。根據(jù) CSS 的特定性規(guī)則,它還可以覆蓋任何其他 CSS 全局規(guī)則。

It is not recommended to scope global styles. A common method for defining global styling is to separate these styles into another style sheet and import them into your App.vue file.

不建議對全局樣式設(shè)置范圍。定義全局樣式的常用方法是將這些樣式分離到另一個樣式表中,然后導(dǎo)入到 App.vue 文件中。

Now, let’s practice importing SCSS, a pre-processor plugin for CSS, to use in your application, and write some scoped stylings with the following exercise.

現(xiàn)在,讓我們練習(xí)導(dǎo)入 SCSS(CSS 的預(yù)處理器插件)到應(yīng)用程序中,并通過下面的練習(xí)編寫一些范圍樣式。

練習(xí):使用SCSS

In this exercise, we will be utilizing the style tag to add SCSS preprocessed styles to a component and importing external stylesheets.

在本練習(xí)中,我們將利用樣式標(biāo)簽為組件添加 SCSS 預(yù)處理樣式,并導(dǎo)入外部樣式表。

Create a new Vue component file named Exercise1-11.vue in the src/components directory.

在 src/components 目錄中新建一個名為 Exercise1-11.vue 的 Vue 組件文件。

在App.vue中引入該組件并渲染:

<script setup>
import Exercise from "./components/Exercise1-11.vue";
</script>
<template>
  <Exercise/>
</template>

Inside Exercise1-11.vue, let’s write some HTML that can be styled using SCSS. Let’s keep practicing the interpolation method:

在 Exercise1-11.vue 中,讓我們編寫一些可以使用 SCSS 定型的 HTML。讓我們繼續(xù)練習(xí)插值法:

<template>
  <div>
    <h1>{{ title }}</h1>
    <h2>{{ subtitle }}</h2>
    <ul>
      <li>{{ items[0] }}</li>
      <li>{{ items[1] }}</li>
      <li>{{ items[2] }}</li>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      title: 'My list component!',
      subtitle: 'Vue JS basics',
      items: ['Item 1', 'Item 2', 'Item 3']
    }
  },
}
</script>

Add the sass SCSS package as a project dependency:

將 sass SCSS 軟件包添加為項目依賴關(guān)系:

npm install -D sass

# 或者
npm add -D sass

# 或者
yarn add sass

Add the lang attribute to the style tag and add the scss value to enable SCSS syntax inside the style block:

在樣式標(biāo)簽中添加 lang 屬性,并添加 scss 值,以便在樣式塊中啟用 SCSS 語法:

<style lang="scss"></style>

Create a folder inside the src/ directory called styles. Inside this new folder, create a file called typography.scss.

在 src/ 目錄下創(chuàng)建一個名為 styles 的文件夾。在這個新文件夾中,創(chuàng)建一個名為 typography.scss 的文件。

Inside typography.scss, add some styling for the template you composed in your component, such as defining color variables (green, grey, and blue) to reuse in different areas of related CSS rules, and some CSS styles for h1, h2, and the list elements:

在 typography.scss 中,為組件中的模板添加一些樣式,例如定義顏色變量(綠色、灰色和藍(lán)色),以便在相關(guān) CSS 規(guī)則的不同區(qū)域重復(fù)使用,以及為 h1、h2 和列表元素添加一些 CSS 樣式:

/* typography.scss */
$color-green: #4fc08d;
$color-grey: #2c3e50;
$color-blue: #003366;
h1 {
  margin-top: 60px;
  text-align: center;
  color: $color-grey;
  + h2 {
    text-align: center;
    color: $color-green;
  }
}
ul {
  display: block;
  margin: 0 auto;
  max-width: 400px;
  padding: 30px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  > li {
    color: $color-grey;
    margin-bottom: 4px;
  }
}

In SCSS, you can use standard CSS selectors to select elements in your component.

在 SCSS 中,您可以使用標(biāo)準(zhǔn) CSS 選擇器來選擇組件中的元素。

ul > li will select every <li> element inside of an <ul> element for styling. Similarly, using the addition symbol (+) means that the elements placed after the first element will be styled if they match the condition. For example, h1 + h2 will dictate that all h2 elements after h1 will be styled in a certain way, but h3 will not. You can understand this better through the following example.

ul > li 將選擇 <ul> 元素內(nèi)的每個 <li> 元素進(jìn)行樣式設(shè)置。同樣,使用加號 (+) 表示,如果第一個元素之后的元素符合條件,那么這些元素就會被樣式化。例如,h1 + h2 表示 h1 之后的所有 h2 元素都將以某種方式進(jìn)行樣式調(diào)整,但 h3 則不會。通過下面的示例,您可以更好地理解這一點。

In CSS, you would present this code as follows:

在 CSS 中,您可以使用如下代碼來呈現(xiàn)這段代碼:

h1 + h2 {
/* Add styling */
}
ul > li {
/* Add styling */
}

In SCSS, the same code can be represented as follows:

在 SCSS 中,同樣的代碼可以表示如下:

h1 {
  + h2 {
  // Add styling
  }
}
ul {
  > li {
  // Add styling
  }
}

In your component, import these styles by using the SCSS @import method:

在組件中,使用 SCSS @import 方法導(dǎo)入這些樣式:

<style lang="scss">
@import '../styles/typography.scss';
</style>

Add the scoped attribute to your <style> tag to only apply these styles to this component instance. Use the variable from the $color-blue imported stylesheet:

<style> 標(biāo)簽中添加作用域?qū)傩?,以便僅將這些樣式應(yīng)用于該組件實例。使用從 $color-blue 導(dǎo)入的樣式表中的變量:

<style lang="scss" scoped>
@import '../styles/typography';
h1 {
  font-size: 50px;
  color: $color-blue; // Use variables from imported stylesheets
}
</style>

到此這篇關(guān)于在Vue3中使用SCSS編寫樣式的文章就介紹到這了,更多相關(guān)Vue3編寫樣式內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue2.0開發(fā)實踐總結(jié)之疑難篇

    vue2.0開發(fā)實踐總結(jié)之疑難篇

    這篇文章主要為大家總結(jié)了vue2.0開發(fā)實踐的疑難,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • element-ui 遠(yuǎn)程搜索組件el-select在項目中組件化的實現(xiàn)代碼

    element-ui 遠(yuǎn)程搜索組件el-select在項目中組件化的實現(xiàn)代碼

    這篇文章主要介紹了element-ui 遠(yuǎn)程搜索組件el-select在項目中組件化,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • 修改vue+webpack run build的路徑方法

    修改vue+webpack run build的路徑方法

    今天小編就為大家分享一篇修改vue+webpack run build的路徑方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue使用urlEncode問題

    vue使用urlEncode問題

    這篇文章主要介紹了vue使用urlEncode問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue3 el-form-item如何自定義label標(biāo)簽內(nèi)容

    vue3 el-form-item如何自定義label標(biāo)簽內(nèi)容

    這篇文章主要介紹了vue3 el-form-item如何自定義label標(biāo)簽內(nèi)容問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue 使用moment獲取當(dāng)前時間及一月前的時間

    vue 使用moment獲取當(dāng)前時間及一月前的時間

    開發(fā)中會有要獲取當(dāng)前日期的需求,有的是獲取到當(dāng)前月份,本文就介紹了vue獲取當(dāng)前日期時間(moment、new?Date()),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2023-08-08
  • Vue如何獲取new Date().getTime()時間戳

    Vue如何獲取new Date().getTime()時間戳

    在Web開發(fā)中,前端使用Vue.js獲取的是毫秒級時間戳,而PHP后端則是秒級時間戳,處理此類問題時,需要將PHP的時間戳乘以1000轉(zhuǎn)換為毫秒級,以保證數(shù)據(jù)的一致性和正確的邏輯判斷
    2024-10-10
  • vue-upload上傳圖片詳細(xì)使用方法

    vue-upload上傳圖片詳細(xì)使用方法

    這篇文章主要介紹了使用vue-upload上傳圖片的詳細(xì)使用說明,文中有相關(guān)的代碼示例供大家參考,感興趣的小伙伴一起跟著小編來學(xué)習(xí)吧
    2023-05-05
  • vue+axios+java實現(xiàn)文件上傳功能

    vue+axios+java實現(xiàn)文件上傳功能

    這篇文章主要為大家詳細(xì)介紹了vue+axios+java實現(xiàn)文件上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • vue3中ref和reactive的區(qū)別舉例詳解

    vue3中ref和reactive的區(qū)別舉例詳解

    ref和reactive是Vue3中構(gòu)建響應(yīng)式數(shù)據(jù)的兩大核心 API,雖然它們在使用上相似,但底層機(jī)制和適用場景有明顯不同,這篇文章主要介紹了vue3中ref和reactive區(qū)別的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-06-06

最新評論

来凤县| 白银市| 上饶市| 庆阳市| 济源市| 开封县| 龙门县| 延长县| 玉林市| 德州市| 巴东县| 阿坝| 大理市| 监利县| 东乌珠穆沁旗| 中西区| 安龙县| 桐庐县| 慈利县| 运城市| 黄山市| 定南县| 英吉沙县| 闸北区| 霍邱县| 普兰县| 时尚| 湘阴县| 乐亭县| 海伦市| 沾化县| 邓州市| 漯河市| 安福县| 双鸭山市| 诏安县| 齐河县| 肥西县| 闵行区| 牙克石市| 崇礼县|