【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 展示

相关推荐
宠友信息1 小时前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”1 小时前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
局外人LZ1 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅1 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥1 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
wangjun51591 天前
uniapp uni.downloadFile 偶发性下载文件失败 无响应
uni-app
2501_915106322 天前
当 Perfdog 开始收费之后,我重新整理了一替代方案
android·ios·小程序·https·uni-app·iphone·webview
2501_915918412 天前
中小团队发布,跨平台 iOS 上架,证书、描述文件创建管理,测试分发一体化方案
android·ios·小程序·https·uni-app·iphone·webview