【uniapp】设置公共样式,实现公共背景等

目录

[1、 全局渐变背景色](#1、 全局渐变背景色)

[2.1 创建common目录](#2.1 创建common目录)

[2.2 在common下新建style和images等目录](#2.2 在common下新建style和images等目录)

[2.3 在style下新建common-style.scss](#2.3 在style下新建common-style.scss)

[2.4 common-style输入全局渐变颜色](#2.4 common-style输入全局渐变颜色)

[2.5 引入样式](#2.5 引入样式)

[2.6 业务页面引入](#2.6 业务页面引入)

[2.7 展示](#2.7 展示)

2、全局字体颜色

[2.1 新建base-style.scss文件](#2.1 新建base-style.scss文件)

[2.2 设置base-style.scss](#2.2 设置base-style.scss)

[2.3 引入base-style.scss](#2.3 引入base-style.scss)

[2.4 页面引用](#2.4 页面引用)

[2.5 展示](#2.5 展示)



前言:通过uniapp四线全局背景样式等,static目录会在打包的时候必打入,新增一个目录按需导入,减少打包文件大小

1、 全局渐变背景色

2.1 创建common目录

根目录新增common目录

2.2 在common下新建style和images等目录

依据需要新增

2.3 在style下新建common-style.scss

2.4 common-style输入全局渐变颜色

复制代码
view,swiper,swiper-item{
	box-sizing: border-box;
}

.pageBg{
	background: 
	linear-gradient(to bottom,transparent,#fff 400rpx),
	linear-gradient(to right,#beecd8, 20%,#F4E2D8);
	min-height: 80vh;
}

2.5 引入样式

App.vue输入

复制代码
<style lang="scss">
	/*每个页面公共css */
	@import 'common/style/common-style.scss';
</style>

2.6 业务页面引入

复制代码
<template>
<view class="pageBg">
	<view class="page-container">
	  <input type="text" placeholder="Enter word or phrase" v-model="word" />
	  <pronunciation :word="word" />
	</view>
</view>

</template>

<script setup>
import { ref } from 'vue';
import Pronunciation from '@/components/YouDaoModal/YouDaoModal.vue'; // 假设你的组件在 components 目录下

const word = ref(''); // 使用 ref 来创建一个响应式变量
</script>

<style scoped>
.page-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
}

input {
  margin-bottom: 10px;
  padding: 10px;
  font-size: 16px;
  width: 80%;
  height: 80rpx;
}
</style>

2.7 展示

2、全局字体颜色

2.1 新建base-style.scss文件

在common-》style 下新建base-style.scss文件

2.2 设置base-style.scss

复制代码
$brand-theme-color: #01ccb6;      // 品牌主体颜色(青绿色)  
$border-color: #e0e0e0;           // 边框颜色  
$border-color-light: #efefef;     // 边框亮色  
$text-font-color-1: #000;         // 文字主色(黑色)  
$text-font-color-2: #676767;      // 副标题颜色(深灰色)  
$text-font-color-3: #a7a7a7;      // 浅色(中灰色)  
$text-font-color-4: #e4e4e4;      // 更浅的颜色(浅灰色)

2.3 引入base-style.scss

在uni.scss中引入base-tyle.scss

复制代码
/* 引入外部 */
@import "@/common/style/base-style.scss";

2.4 页面引用

在page下页面引用(pages.json页面不行哦)

复制代码
	.top-view {
		// background-color: #01ccb6;
		// color: white;
		color: $text-font-color-4;
		padding: 40rpx;
	}

2.5 展示

相关推荐
willow5 小时前
uniapp实战
uni-app
只会cv的前端攻城狮6 小时前
兼容性地狱-Uniapp钉钉小程序环境隔离踩坑实录
前端·uni-app
codingWhat2 天前
小程序里「嵌」H5:一套完整可落地的 WebView 集成方案
前端·uni-app·webview
小时前端3 天前
微信小程序选不了本地文件?用 web-view + H5 一招搞定
前端·微信小程序·uni-app
Mr_li4 天前
给 Vue 开发者的 uni-app 快速指南
vue.js·uni-app
anyup4 天前
🔥2026最推荐的跨平台方案:H5/小程序/App/鸿蒙,一套代码搞定
前端·uni-app·harmonyos
Mintopia5 天前
Vue3 项目如何迁移到 uni-app x:从纯 Web 到多端应用的系统指南
uni-app
Mintopia5 天前
uni-app x 发展前景技术分析:跨端统一的新阶段?
uni-app
不爱说话郭德纲6 天前
告别漫长的HbuilderX云打包排队!uni-app x 安卓本地打包保姆级教程(附白屏、包体积过大排坑指南)
android·前端·uni-app
HashTang7 天前
【AI 编程实战】第 12 篇:从 0 到 1 的回顾 - 项目总结与 AI 协作心得
前端·uni-app·ai编程