封装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>
相关推荐
天外飞雨道沧桑8 小时前
TypeScript 中 omit 和 record 用法
前端·javascript·typescript
kkeeper~9 小时前
0基础C语言积跬步之深入理解指针(5下)
c语言·开发语言
一直不明飞行9 小时前
Java的equals(),hashCode()应该在什么时候重写
java·开发语言·jvm
盲敲代码的阿豪9 小时前
Python 入门基础教程(爬虫前置版)
开发语言·爬虫·python
basketball61610 小时前
C++ 构造函数完全指南:从入门到进阶
java·开发语言·c++
互联科技报10 小时前
2026超融合选型:Top5品牌与市场格局解读
开发语言·perl
weixin1997010801610 小时前
[特殊字符] 智能数据采集:数字化转型的“数据石油勘探队”(附Python实战源码)
开发语言·python
想唱rap10 小时前
IO多路转接之poll
服务器·开发语言·数据库·c++
暗冰ཏོ11 小时前
VUE面试题大全
前端·javascript·vue.js·面试
@杰克成11 小时前
Java学习30
java·开发语言·学习