vue3 baseCss 初始化

39 篇文章 0 订阅

初始化 scss less

1 项目 通用样式 初始化

  1 自定义重置样式代码 公用样式代码
  common.less
  
  通用样式
  2 normalize.css
  npm i normalize.css
  
  normalize.css 可以补充 common 样式  比如  body margin { margin: 0; }
  只给body设置颜色会传递给html( margin: 8px; 也看不出来) 分别设置就会 各自有自己的颜色

  3 main.js 中导入
  import 'normalize.css'
  import '@/assets/styles/common.less'

  4 或者 取消 3  在 vue.config.js  配置 全局sass变量   
    在 common 中 引入 @import 'normalize.css'; 或者 直接 vue.config.js--additionalData中配置
   	css: {
		loaderOptions: {
			scss: {
				// 全局sass变量
				additionalData: `@import "~@/assets/styles/common.scss";
				                 @import "normalize.css";`,
			},
		},
	},
   还有其他的  ` ; ` 
   
   重点 !!!  否则无效
   App.vue  中  style 必须有内容  // 也可
   <style scope lang="scss">
   //
    </style>


  自定义样式 变量  每次使用  必须导入
  @import "mixins.less";
  自动化导入--style-resources-loader
  步骤
  1 安装 插件 vue add style-resources-loader
  选择 less
  2 vue.config.js 中  哪些文件自动导入 使用绝对路径
pluginOptions: {
		'style-resources-loader': {
			preProcessor: 'less',

    	   哪些文件自动导入 使用绝对路径
			   使用 path.join 来拼接完整路径

			patterns: [
				path.join(__dirname, './src/assets/styles/variables.less'),
				path.join(__dirname, './src/assets/styles/mixins.less'),
			],
		},
	},

src–assets–styles–common.less

// 重置样式
* {
	box-sizing: border-box;
}

html {
	height: 100%;
	font-size: 14px;
}
body {
	height: 100%;
	color: #333;
	min-width: 1240px;
	font: 1em/1.4 'Microsoft Yahei', 'PingFang SC', 'Avenir', 'Segoe UI',
		'Hiragino Sans GB', 'STHeiti', 'Microsoft Sans Serif', 'WenQuanYi Micro Hei',
		sans-serif;
}

ul,
h1,
h3,
h4,
p,
dl,
dd {
	padding: 0;
	margin: 0;
}
a {
	text-decoration: none;
	color: #333;
	outline: none;
}
i {
	font-style: normal;
}
input[type='text'],
input[type='search'],
input[type='password'],
input[type='number'],
input[type='checkbox'] {
	padding: 0;
	outline: none;
	border: none;
	-webkit-appearance: none;
	&::placeholder {
		color: #ccc;
	}
}

// input改为number类型,去掉上下箭头
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
	-webkit-appearance: none !important;
}
input[type='number'] {
	-moz-appearance: textfield;
}
img {
	max-width: 100%;
	max-height: 100%;
	vertical-align: middle;
	//  background: #ebebeb url(../assets/images/200.png) no-repeat center / contain;
}
ul {
	list-style: none;
}
#app {
	background: #f5f5f5;
	// none   无法选中
	user-select: auto;
}

.container {
	width: 1240px;
	margin: 0 auto;
	position: relative;
}
//  文本超过后加上省略号
.ellipsis {
	white-space: nowrap;
	text-overflow: ellipsis;
	overflow: hidden;
}

.ellipsis-2 {
	word-break: break-all;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
}

.fl {
	float: left;
}

.fr {
	float: right;
}

.clearfix:after {
	content: '.';
	display: block;
	visibility: hidden;
	height: 0;
	line-height: 0;
	clear: both;
}
// 主页 新鲜好物骨架屏  离开
.fade {
	&-leave {
		&-active {
			position: absolute;
			width: 100%;
			transition: opacity 0.5s 0.2s;
			z-index: 1;
		}
		&-to {
			opacity: 0;
		}
	}
}
// 面包屑 动画
// 旧元素 0-->20px 新元素 20px-->0
.fade-right {
	&-enter-from,
	&-leave-to {
		opacity: 0;
		transform: translateX(20px);
	}
	&-enter-active,
	&-leave-active {
		transition: all 0.5s;
	}
	&-enter-to,
	&-leave-from {
		opacity: 1;
		transform: translateX(0);
	}
}
// 公用的  表单  Form, Field  样式
//  Form, Field -->xtx-form-->xtx-form-item
.xtx-form {
	width: 700px;
	margin: 0 auto;
	padding-left: 190px;
	line-height: 50px;
	&-item {
		display: flex;
		align-items: center;
		margin-bottom: 25px;
		.input {
			position: relative;
			// height: 50px;
			> i {
				position: absolute;
				left: 1px;
				top: 1px;
				width: 49px;
				height: 48px;
				color: #999;
				text-align: center;
				line-height: 48px;
				font-size: 18px;
			}
			// 输入框
			input {
				height: 50px;
				width: 320px;
				padding-left: 50px;
				border: 1px solid #e4e4e4;
				border-radius: 4px;
				&.errors {
					border-color: @priceColor;
				}
				&.active,
				&:focus {
					border-color: @xtxColor;
				}
			}
			// 短信验证码按钮
			.code {
				position: absolute;
				right: 1px;
				top: 1px;
				width: 80px;
				height: 48px;
				text-align: center;
				line-height: 48px;
				font-size: 14px;
				background: #f5f5f5;
				color: #666;
				cursor: pointer;
			}
		}
		//  错误提示
		.error {
			line-height: 28px;
			color: @priceColor;
			i {
				font-size: 16px;
				margin: 0 1px 0 8px;
			}
		}
	}
	.submit {
		display: block;
		width: 320px;
		height: 50px;
		color: #fff;
		font-size: 16px;
		text-align: center;
		background: @xtxColor;
		border-radius: 4px;
		&.disabled {
			background: #cfcdcd;
		}
	}
}

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
搭建 Vue3 项目需要以下步骤: 1. 新建一个项目文件夹,比如 my-project,进入该文件夹,使用 `npm init` 初始化项目。 2. 安装 webpack、webpack-cli、vue-loader、vue-template-compiler、webpack-dev-server、css-loader、style-loader、postcss-loader、autoprefixer、babel-loader 和相关的 preset 和 plugin,比如: ``` npm install webpack webpack-cli vue-loader vue-template-compiler webpack-dev-server css-loader style-loader postcss-loader autoprefixer babel-loader @babel/core @babel/preset-env @babel/plugin-transform-runtime -D ``` 3. 在项目根目录下新建一个 webpack.config.js 文件,配置 webpack: ```javascript const path = require('path'); const { VueLoaderPlugin } = require('vue-loader'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const webpack = require('webpack'); module.exports = { entry: './src/main.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', }, { test: /\.js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'], plugins: ['@babel/plugin-transform-runtime'], }, }, }, { test: /\.css$/, use: ['style-loader', 'css-loader', 'postcss-loader'], }, ], }, plugins: [ new VueLoaderPlugin(), new HtmlWebpackPlugin({ template: './public/index.html', }), new webpack.DefinePlugin({ __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false, }), ], devServer: { contentBase: path.join(__dirname, 'public'), compress: true, port: 9000, }, }; ``` 4. 在项目根目录下新建一个 public 文件夹,其中包含一个 index.html 文件,比如: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>My App</title> </head> <body> <div id="app"></div> <script src="./dist/bundle.js"></script> </body> </html> ``` 5. 在项目根目录下新建一个 src 文件夹,其中包含一个 main.js 文件,比如: ```javascript import { createApp } from 'vue'; import App from './App.vue'; createApp(App).mount('#app'); ``` 6. 在 src 文件夹下新建一个 App.vue 文件,比如: ```html <template> <div class="app"> <h1>{{ msg }}</h1> </div> </template> <script> export default { data() { return { msg: 'Hello, Vue3!', }; }, }; </script> <style scoped> .app { text-align: center; } </style> ``` 7. 在 package.json 中添加以下脚本: ```json "scripts": { "dev": "webpack serve --mode development", "build": "webpack --mode production" } ``` 然后使用 `npm run dev` 启动开发服务器,使用 `npm run build` 打包项目。 这样就完成了 Vue3 + webpack 的项目搭建。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值