Vue和Element UI 路由跳转,侧边导航的路由跳转,侧边栏拖拽

 首先看布局,因为我的用于页面显示的 <router-view> 是通过重定向定位到登陆页的,然后通过登陆页跳转到主页。项目中用到了点击侧边栏的跳转,所以记录下来,方便有需要的人用到~

  1. 阐述
    (1).content{ display:flex;} 一定要有,否则在拖拽时会出现换行的情况
    (2)resize 要相对于父级绝对定位

<template>
	<!--	<div class="el-dialog__header">-->

	<!--	</div>-->
	<div >
		<!--搜索框-->
		<div class="top-wrapper ">
			<div class="search el-input el-input--suffix">
				<input
					type="text"
					autocomplete="off"
					placeholder="输入指标名称搜索"
					class="el-input__inner"
				/>
			</div>
		</div>
		<!--中部-->
		<div class="indicator-wrapper">
			<!--侧边栏   -->
			<div class="indicator-side">
				<a
					:class="{ 'indicator-category': true, 'indicator-category-active': item.checked }"
					v-for="item in sideList"
					:key="item.id"
					@click.prevent="categoryClick(item)"
					href="#!"
				>
					{{ item.name }}
				</a>
			</div>
			<!--中间选择器   -->
			<div class="indicator-body">
				<div class="indicator-block"
					 v-for="item in sideList"
					 :key="item.id" :id="'chen'+ item.id">
					<div class="indicator-group">
						<span class="indicator-title">{{ item.name }} </span>
					</div>
					<div class="el-row">
						<div class="el-col el-col-8" v-for="el in item.child " :key="el.id">
							<el-checkbox v-model="el.checked" class="el-checkbox__input el-checkbox"
							><span class="el-checkbox__label">{{ el.name }}</span></el-checkbox>
						</div>
					</div>
				</div>
			</div>
			<!--拖拽-->
			<div class="flex ">
				<div class="indicator-drag">
					<div class="indicator-content">
						<div class="drag-title">已选指标</div>
						<div class="drag-sec">拖动可自定义指标顺序</div>
						<div class="indicator-limit_low">
							<div class="drag-block not-allow mg2">账户名称</div>
						</div>
						<div class="drag-sepreate">以上指标将横向固定</div>
					</div>
					<div class="indicator-limit-many" style="max-height: 445px">
						<section
							v-draggable="[
							drag,
							{
								animation: 150,
								ghostClass: 'ghost',
								group: 'people',
								onUpdate,
								onAdd,
								onRemove
							}
						]"
							class="flex flex-col gap-2 p-4 w-300px h-300px m-auto bg-gray-500/5 rounded overflow-auto"
						>
							<div
								v-for="item in drag"
								:key="item.id"
								class="drag-block hover-class all-scroll mg2"
								@click="dragClick(item)"
							>
								{{ item.name
								}}
								<el-icon
									@click="removeItem(item.id)"
									style="
									float: right;
									align-items: center;
									position: relative;
									top: 8px;
								"
									class="mg-icon-close close"
								>
									<close
									/>
								</el-icon>
							</div>
						</section>
						<div class="flex justify-between">
							<preview-list :list="drag" />
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { vDraggable } from "vue-draggable-plus";
import { Close } from "@element-plus/icons-vue";

const sideList = ref([
	{
		id: 1,
		name: "基本信息",
		child: [
			{
				id: 1,
				name: "账号名称"
			},
			{
				id: 2,
				name: "账户ID"
			},
			{
				id: 3,
				name: "账户主体"
			}
		]
	},
	{
		id: 2,
		name: "财务流水",
		child: [
			{
				id: 1,
				name: "共享赠款支出(¥)"
			},
			{
				id: 2,
				name: "账户总支出"
			},
			{
				id: 3,
				name: "账户现金支出"
			}
		]
	},
	{
		id: 3,
		name: "展现数据",
		child: [
			{
				id: 1,
				name: "消耗"
			},
			{
				id: 2,
				name: "展示数"
			},
			{
				id: 3,
				name: "平均千次展现费用"
			}
		]
	},
	{
		id: 4,
		name: "转化数据",
		child: [
			{
				id: 1,
				name: "转换数"
			},
			{
				id: 2,
				name: "转换陈本"
			},
			{
				id: 3,
				name: "转换率"
			}
		]
	},
	{
		id: 5,
		name: "转化数据(计费时间)",
		child: [
			{
				id: 1,
				name: "转化数(计费时间)"
			},
			{
				id: 2,
				name: "转化成本(计费时间)"
			},
			{
				id: 3,
				name: "深度转化次数(计费时间)"
			}
		]
	},
	{
		id: 6,
		name: " APP下载数据",
		child: [
			{
				id: 1,
				name: "安卓下载开始数"
			},
			{
				id: 2,
				name: "安卓下载开始成本"
			},
			{
				id: 3,
				name: "安卓下载开始率"
			}
		]
	},
	{
		id: 7,
		name: "视频数据",
		child: [
			{
				id: 1,
				name: "播放数"
			},
			{
				id: 2,
				name: "有效播放数"
			},
			{
				id: 3,
				name: "有效播放率"
			}
		]
	},
	{
		id: 8,
		name: "落地页及门店数据",
		child: [
			{
				id: 1,
				name: "点击电话按钮"
			},
			{
				id: 2,
				name: "表单提交"
			},
			{
				id: 3,
				name: "地图搜索"
			}
		]
	},
	{
		id: 9,
		name: "附加创意",
		child: [
			{
				id: 1,
				name: "附加创意电话按钮点击"
			},
			{
				id: 2,
				name: "附加创意在线咨询点击"
			},
			{
				id: 3,
				name: "附加创意表单按钮点击"
			}
		]
	},
	{
		id: 10,
		name: "互动数据",
		child: [
			{
				id: 1,
				name: "新增关注数"
			},
			{
				id: 2,
				name: "点赞数"
			},
			{
				id: 3,
				name: "评论提交数"
			}
		]
	},
	{
		id: 11,
		name: " 直播间数据",
		child: [
			{
				id: 1,
				name: "直播间观看数"
			},
			{
				id: 2,
				name: "直播间超过1分钟观看数"
			},
			{
				id: 3,
				name: "直播间关注数"
			}
		]
	},
	{
		id: 12,
		name: "游戏行业",
		child: [
			{
				id: 1,
				name: "当日付费金额"
			},
			{
				id: 2,
				name: "当日付费ROI"
			},
			{
				id: 3,
				name: "激活24h首次付费数"
			}
		]
	},
	{
		id: 13,
		name: "线索收集",
		child: [
			{
				id: 1,
				name: "有效获客"
			},
			{
				id: 2,
				name: "乘客首次下单数"
			},
			{
				id: 3,
				name: "回访—加好友(计费时间)"
			}
		]
	}
]);

const categoryClick = (item) => {
	sideList.value.forEach((el) => (el.checked = false));
	item.checked = !item.checked;
	const element = document.getElementById("chen" + item.id);
	if (element) {
		element.scrollIntoView({ behavior: "smooth" });
	}

};

const count = ref(0);

const removeItem = (id) => {
	drag.value = drag.value.filter(item => item.id != id);


};
// const domeRef = ref<HTMLElement | null>(null);
// const handleClick = (MouseEvent) => {
// 	e.preventDefault();
// };
//拖拽
const drag = ref([
	{
		id: 1,
		name: "账户ID"
	},
	{
		id: 2,
		name: "备注"
	},
	{
		id: 3,
		name: "项目"
	},
	{
		id: 4,
		name: "登录邮箱"
	},
	{
		id: 5,
		name: "账户余额(元)"
	},
	{
		id: 6,
		name: "消耗"
	},
	{
		id: 7,
		name: "点击率"
	},
	{
		id: 8,
		name: "深度转化成本"
	},
	{
		id: 9,
		name: "首次付费率"
	},
	{
		id: 10,
		name: "APP内访问"
	},
	{
		id: 11,
		name: "app内下单"
	}
]);
const dragClick = (item) => {
	drag.value.forEach((el) => (el.checked = false));
	item.checked = !item.checked;
};

function onUpdate() {
	console.log("update");
}

function onAdd() {
	console.log("add");
}

function onRemove() {
	console.log("remove");
}
</script>

<style scoped lang="scss">
::v-deep .el-scrollbar {
	overflow: hidden;
	height: 100%;
	position: static !important;
}

::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
	background-color:  #409eff;;
	//border-color: var(--el-checkbox-checked-input-border-color);
}
//隐藏滚动条
::-webkit-scrollbar-thumb {
	border-radius: 5px;
	background-color: rgb(255, 255, 255, 0.2);;
}

::-webkit-scrollbar {
	width: 10px;
	height: 10px;
}
//搜索框
.top-wrapper {
	display: flex;
	justify-content: flex-start;
	margin-bottom: 16px;
}

.top-wrapper .search {
	width: 250px;
}

.el-input {
	position: relative;
	font-size: 14px;
}

.el-input__inner {
	-webkit-appearance: none;
	background-color: #fff;
	background-image: none;
	border-radius: 4px;
	border: 1px solid #dcdfe6;
	box-sizing: border-box;
	color: #606266;
	display: inline-block;
	height: 40px;
	line-height: 40px;
	outline: 0;
	padding: 0 15px;
	transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
	width: 100%;
	font-size: inherit;
	-webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}
.el-dialog .el-dialog__body .el-input .el-input__inner {
	padding-left: 8px;
	color: #333;
}

.el-input .el-input__inner {
	height: 32px;
	line-height: 32px;
	border-radius: 2px;
}

//侧边栏
.indicator-side .indicator-category {
	padding-left: 16px;
	font-size: 14px;
	line-height: 40px;
	color: #333;
	cursor: pointer;
	display: block;
}

.indicator-side .indicator-category-active {
	color: #197afb;
	background-color: #d6eaff;
}

//中间基本信息
.indicator-block {
	padding: 16px 0 0 24px;
	border-bottom: 1px solid #eaebec;
}

.indicator-group {
	display: flex;
	justify-content: flex-start;
}

.indicator-title {
	margin-bottom: 16px;
	font-weight: 700;
	color: #333;
}

.el-checkbox__input.is-checked .el-checkbox__label{
	color: #409eff;
}

.el-checkbox__label {
	color: #333;
}

.el-checkbox__label,
.el-radio__label {
	font-size: 12px;
	color: #666;
}

.el-checkbox__label {
	display: inline-block;
	padding-left: 1px;
	line-height: 19px;
	font-size: 12px;
}

//拖拽
.indicator-drag .indicator-content {
	padding: 0 16px;
}

.indicator-drag .drag-title {
	font-size: 14px;
	font-weight: 700;
	line-height: 100%;
	color: #333;
}

.indicator-drag .drag-sec {
	margin: 8px 0;
	font-size: 12px;
	line-height: 100%;
	color: #999;
}
.indicator-drag .drag-sepreate {
	position: relative;
	margin: 16px 0 0;
	font-size: 12px;
	color: #999;
	text-align: center;
}

.indicator-drag .indicator-limit-many {
	max-height: 445px;
	padding: 0 16px;
	margin-top: 16px;
	overflow-x: hidden;
	overflow-y: auto;
}


.indicator-drag .mg2 {
	margin-bottom: 2px;
}

.indicator-drag .drag-block {
	position: relative;
	height: 40px;
	//width: 134px;
	padding: 0 30px 0 36px;
	overflow: hidden;
	line-height: 40px;
	text-overflow: ellipsis;
	white-space: nowrap;
	background-color: #fff;
	border-bottom: 1px solid #e8eaec;
}


.indicator-drag .drag-block .close {
	position: absolute;
	top: 13px;
	line-height: 100%;
	color: #cecece;
	cursor: pointer;
}

//滑动条
.infinite-list {
	width: 160px;
	height: 300px;
	padding: 0;
	margin: 0;
	list-style: none;
}

.infinite-list .infinite-list-item {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 40px;
	padding-left: 16px;
	font-size: 14px;
	background: #409eff;
	margin: 10px;
	color: #409eff;
}

.infinite-list .infinite-list-item + .list-item {
	margin-top: 10px;
}

//中部
.indicator-wrapper {
	display: flex;
	width: 832px;
	height: 516px;
	border: 1px solid #eaebec;
	border-radius: 4px;

}

//侧边栏
.indicator-side {
	flex-shrink: 0;
	width: 160px;
	overflow: auto;
	border-right: 1px solid #eaebec;
}

//选择器
.indicator-body {
	width: 672px;
	overflow: auto;
	scroll-behavior: smooth;
}

//右边
.indicator-drag {
	position: absolute;
	top: 0;
	right: 0;
	flex-shrink: 0;
	width: 216px;
	//height: 676px;
	padding: 25px 0;
	overflow: auto;
	background-color: #f8f8f9;
	border-right: 1px solid #eaebec;
}
</style>

Vue中配置侧边栏路由跳转的步骤如下: 1. 首先,在router文件夹下创建一个index.js文件来管理路由。在该文件中,使用VueRouter插件,并导出一个新的VueRouter实例。在routes数组中定义各个路由的路径、名称和组件。例如,可以定义一个名为Main的路由,其路径为'/',组件为Main.vue。在Main路由下可以再定义子路由,如Home和User。\[1\] 2. 在App.vue文件中,修改模板部分,添加<router-view>标签,用于显示当前路由对应的组件。\[1\] 3. 在CommandAside.vue文件中,进行路由配置。可以引入element-ui侧边栏组件等。\[1\] 4. 在终端中使用npm install命令安装vue-router插件,可以指定版本号。例如,使用npm install vue-router@4安装vue-router的4版本。\[2\] 5. 在main.js文件中,配置路由。首先引入Vue和App.vue组件,然后引入element-ui,并使用Vue.use(ElementUI)来全局引入element-ui。最后创建一个新的Vue实例,将router对象传入,并将App组件渲染到#app元素中。\[2\] 以上是在Vue中配置侧边栏路由跳转的基本步骤。具体的代码实现可以参考上述引用的内容。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [vue基于element路由侧边栏名字跳转](https://blog.csdn.net/m0_61686427/article/details/124437154)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Vue3项目-侧边栏跳转](https://blog.csdn.net/dayouan/article/details/129876149)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值