【VUE】Vue3+Element Plus动态间距处理

目录

  • [1. 动态间距调整](#1. 动态间距调整)
    • [1.1 效果演示](#1.1 效果演示)
    • [1.2 代码演示](#1.2 代码演示)
  • [2. 固定间距](#2. 固定间距)
    • [2.1 效果演示](#2.1 效果演示)
    • [2.2 代码演示](#2.2 代码演示)
  • 其他情况

1. 动态间距调整

1.1 效果演示

  • 并行效果
  • 并列效果

1.2 代码演示

html 复制代码
<template>

    <div style="margin-bottom: 15px">
        direction:
        <el-radio v-model="direction" value="horizontal">horizontal</el-radio>
        <el-radio v-model="direction" value="vertical">vertical</el-radio>
    </div>
    <div style="margin-bottom: 15px">
        fillRatio:<el-slider v-model="fillRatio" />
    </div>
    <el-space fill wrap :fill-ratio="fillRatio" :direction="direction" style="width: 100%">
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
    </el-space>

</template>
<script setup>
import { ref } from 'vue'

const direction = ref('horizontal')
const fillRatio = ref(10)
</script>
<style lang="scss" scoped></style>

2. 固定间距

2.1 效果演示

2.2 代码演示

其实就是去掉了那个调整标签<el-slider> 等等。

html 复制代码
<template> 
    <el-space fill wrap :fill-ratio="fillRatio" :direction="direction" style="width: 100%">
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
    </el-space>

</template>
<script setup>
import { ref } from 'vue'

const direction = ref('horizontal')
const fillRatio = ref(10)		//重点关注这个值:固定参数
</script>
<style lang="scss" scoped></style>

其他情况

有可能因为内容没占满整行而导致,width: 100% 平铺到整行的情况。如下所示:

解决方案就是:添加<div></div>标签,如:

html 复制代码
    <el-space fill wrap :fill-ratio="fillRatio" :direction="direction" style="width: 100%">
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        <div>
            测试输入框间隔距离:<el-input v-model="input" style="width: 240px;margin-right: 100px ;" placeholder="Please input" />
        </div>
    </el-space>

效果:

这样就好啦~

需要调整的细节在调整一下就ok~

感谢观看~~!

相关推荐
mCell6 小时前
GSAP ScrollTrigger 详解
前端·javascript·动效
gnip6 小时前
Node.js 子进程:child_process
前端·javascript
excel9 小时前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel10 小时前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼12 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping12 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙13 小时前
[译] Composition in CSS
前端·css
白水清风13 小时前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix13 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户221520442780013 小时前
new、原型和原型链浅析
前端·javascript