当前位置: 首页 > article >正文

封装descriptions组件,描述,灵活

效果
在这里插入图片描述
在这里插入图片描述

1、组件1,dade-descriptions.vue

<template>
	<table>
	  <tbody>
		  <slot></slot>
	  </tbody>  
	</table>
</template>

<script>
</script>

<style scoped>
	table {
		width: 100%;
		border-collapse: collapse;
		table-layout: fixed; /* 设置表格布局为固定 */
	}
</style>

2、组件2,dade-descriptions-item.vue

<template>
	<th :style="'width:'+width+'px'">{{label}}</th>
	<td :colspan="colspan">
		<slot></slot>
	</td>
</template>

<script setup>
	import { defineProps } from 'vue';
	// 定义 props
	const props = defineProps({
	  label: {
	    type: String,
	    default: ''
	  },
	  colspan:{
		 type: String,
		 default: '1' 
	  },
	  width:{
		  type: String,
		  default: '100' 
	  }
	});
</script>

<style scoped>
	th,td {
		border: 1px solid rgba(239, 239, 245, 1);
		padding: 0px 4px 0px 0px;
	}
	th {
		/* width: 100px; */
		text-align: left;
		background-color:rgba(250, 250, 252, 1);
		padding: 4px 8px;
	}
</style>

3、组件3,dade-input

<template>
	<input class="dade-input" style="width: 100%;" :type="type" :placeholder="placeholder" :disabled="disabled"/>
</template>

<script setup>
	import { defineProps } from 'vue';
	// 定义 props
	const props = defineProps({
	  placeholder: {
	    type: String,
	    default: ''
	  },
	  type:{
		 type: String,
		 default: 'text' 
	  },
	  disabled:{
		 type: Boolean,
		 default: false 
	  }
	});
</script>

<style scoped>
	.dade-input{
		border: none;
		outline: none;
		padding: 4px 8px;
		border: 1px solid transparent;
		margin: 2px;
	}
	.dade-input:hover {
	    border: 0.5px solid #1ab362c7;
		margin: 2px;
		-webkit-box-shadow: 0 0.1px 0px 0 #1ab362c7;
		box-shadow: 0 0.1px 1.5px 0 #1ab362c7;
	}
	.dade-input:focus {
		border: 0.5px solid #1ab362c7;
		margin: 2px;
		-webkit-box-shadow: 0 0.1px 0px 0 #1ab362c7;
		box-shadow: 0 0.1px 3px 0 #1ab362c7;
	}
</style>

4、全局注册

import './assets/main.css'
import naive from 'naive-ui'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import dadeInput from './common/dade-input.vue'
import dadeDescriptions from './common/descriptions/dade-descriptions.vue'
import dadeDescriptionsItem from './common/descriptions/dade-descriptions-item.vue'


const app = createApp(App)
app.use(naive)
app.use(router)
// 使用 app.component() 注册全局组件
app.component('dade-input', dadeInput)
app.component('dade-descriptions', dadeDescriptions)
app.component('dade-descriptions-item', dadeDescriptionsItem)

app.mount('#app')

5、使用

<template>
  <div>
    <div style="margin-top:10px;width: 100%;">
		<dade-descriptions>
			<tr>
				<dade-descriptions-item label="大得001" width="100">
					<dade-input placeholder="大得" disabled="true"></dade-input>
				</dade-descriptions-item>
				<dade-descriptions-item label="大得001" width="100">
					<div style="padding: 4px 8px;">22</div>
				</dade-descriptions-item>
				<dade-descriptions-item label="大得001" width="150">
					<div style="padding: 4px 8px;">22</div>
				</dade-descriptions-item>
				<dade-descriptions-item label="大得001">
					<div style="padding: 4px 8px;">22</div>
				</dade-descriptions-item>
			</tr>
			<tr>
				<dade-descriptions-item label="大得001"><dade-input placeholder="大得"></dade-input></dade-descriptions-item>
				<dade-descriptions-item label="大得001" colspan="5"><dade-input placeholder="大得"></dade-input></dade-descriptions-item>
			</tr>
			<tr>
				<dade-descriptions-item label="大得001" colspan="7"><dade-input placeholder="大得"></dade-input></dade-descriptions-item>
			</tr>
		</dade-descriptions>
    </div>
  </div>
</template>

<script setup>
</script>

<style scoped>
	
	
</style>

http://www.kler.cn/a/536447.html

相关文章:

  • matlab simulink 汽车四分之一模型轮胎带阻尼
  • STM32的HAL库开发---通用定时器(TIMER)---定时器脉冲计数
  • Baklib赋能数字内容体验个性化推荐提升用户体验的未来之路
  • 什么是自动化测试?自动化测试的作用
  • 8. k8s二进制集群之Kubectl部署
  • PHP JSON操作指南
  • Ansys Maxwell:磁耦合器 - 扭矩与角度分析
  • 800G光模块:引领未来数据中心与网络通信的新引擎
  • GPT-4使用次数有上限吗?一文了解使用规则
  • WPF 进度条(ProgressBar)示例一
  • 【Pandas】pandas Series skew
  • Nginx SSL: error:1410D0B 错误
  • C#+Redis接收数据并定时3秒钟频率异步保存到数据库
  • [Halcon] 灰度值插值介绍
  • 数据库开发常识(10.6)——考量使用多视图连接、循环删除、绑定变量、连接表数及触发器(2)
  • C++ labmbd表达式
  • 在 Flownex 中创建自定义工作液
  • 寻找2020
  • 【算法】动态规划专题⑥ —— 完全背包问题 python
  • Maven 依赖管理全面解析
  • 【有啥问啥】什么是CTC(Connectionist Temporal Classification)算法
  • leetcode_双指针 541. 反转字符串 II
  • KAFKA-UI升级教程,因旧版本不支持(KAFKA-3.8.0 开启SASL认证)
  • Python基于Django的课堂投票系统的设计与实现【附源码】
  • Linux系统用户分类、UID与GID的区别、用户管理的基础命令
  • 【AIGC魔童】DeepSeek v3提示词Prompt书写技巧