vue随意置换页面元素位置

写在前面,博主是个在北京打拼的码农,从事前端工作5年了,做过十多个大大小小不同类型的项目,最近心血来潮在这儿写点东西,欢迎大家多多指教。

  • 对于文章中出现的任何错误请大家批评指出,一定及时修改。
  • 有任何想要讨论和学习的问题可联系我:13287946835@139.com。
  • 发布文章的风格因专栏而异,均自成体系,不足之处请大家指正。

本文关键字:vue,dom元素、页面中的模块随意换位置、通过拖拽改变元素位置、通过拖拽交换元素位置

基本思路:

1.写成渲染函数比较麻烦,一个又一个模块比较复杂,还是用template模版语法渲染比较好

2.所以决定分成多个组件,使用动态组件进行渲染

批量引入探索

批量引入文件夹下的vue文件

 created() {this.requireSvgs();},methods: {// 将引入资源的动作定义成了函数requireSvgs () {const requireAll = requireContext => requireContext.keys().map(requireContext)const req = require.context('./hintSetChild', false, /\.less$/);console.log('req.keys() :>> ', req.keys());requireAll(req)},

报错

This relative module was not found:

* ./common.less in ./src/components/orgOffice/statisticAnalysis/hintSetChild nonrecursive \.less$

项目技术栈版本:

"vue": "^2.6.11",

"webpack": "^3.12.0",

老项目开发起来很难受很难受,web自动导入探索失败,目前认定是webpack版本太低不支持,至少到5版本比较好,

所以最后我并没有进行自动引入

定位跳转 

动态组件引入组件后,通过定位跳转到指定位置

<divv-for="item of modelSortList":key="item.code"@click="gotoView(item.code)">{{ item.shortName }}</div><template v-for="item of modelSortList"><component:createTime="createTime":key="item.code":is="'Chart' + item.code":ref="'Chart' + item.code"></component></template>gotoView(code) {this.$nextTick(() => {const index = "Chart" + code;if (this.$refs[index][0]) {this.$refs[index][0].$el.scrollIntoView();}});},

父组件点击后所有子组件刷新

vue 点击父组件,刷新子组件_AB教程网

排序接口返回内容:

[{"id": "1","code": 1,"name": "单位统计分析","shortName": "单位","sortNum": 7,"delFlag": 0},{"id": "7","code": 1,"name": "舆情处置情况统计报表","shortName": "处置","sortNum": 6,"delFlag": 0},{"id": "2","code": 1,"name": "舆情事件","shortName": "舆情","sortNum": 5,"delFlag": 0},{"id": "3","code": 1,"name": "媒体来源top20","shortName": "媒体","sortNum": 4,"delFlag": 0},{"id": "4","code": 1,"name": "舆情所属条线分析","shortName": "条线","sortNum": 3,"delFlag": 0},{"id": "5","code": 1,"name": "负面类别","shortName": "类别","sortNum": 2,"delFlag": 0},{"id": "6","code": 1,"name": "长期悬而未决事件","shortName": "长期","sortNum": 1,"delFlag": 0}
]

全部代码

<template><divclass="extractCommont extractSearch userControl extractDataMaintenanceSearch specialH"id="container"><div class="with90" style="width:98%"><div><div class="commentInformationSearchBox"><div class="titleLabel set-style-1"><div class="titleLabel col-3"><label class="font-weight">时间范围</label>&nbsp;&nbsp;<el-cascaderplaceholder="请选择":options="timeOption"filterableclearablechange-on-selectv-model="timeRange":props="{emitPath: true}"@change="(timeRangeStart = ''), (timeRangeEnd = '')"></el-cascader><el-radio-groupstyle="width: 120px;"v-model="rangeSet"size="mini"><el-radio-button label="自定义"></el-radio-button></el-radio-group><el-date-picker:picker-options="pickerOptionsEnd"v-if="rangeSet == '自定义'"value-format="yyyy-MM-dd HH:mm:ss"v-model="timeRangeStart"type="datetime"placeholder="开始日期"@change="timeRange = ''"></el-date-picker>&nbsp;<el-date-picker:picker-options="pickerOptionsEnd"v-if="rangeSet == '自定义'"value-format="yyyy-MM-dd HH:mm:ss"v-model="timeRangeEnd"type="datetime"placeholder="结束日期"@change="timeRange = ''"></el-date-picker><label>事发单位</label><el-cascader:options="organization"filterableclearablechange-on-selectv-model="sendOrgId":props="{label: 'name',value: 'id',children: 'childrenList',emitPath: false,expandTrigger: 'hover'}":show-all-levels="false"></el-cascader>&nbsp;<button class="blue" style="height:30px" @click="search()"><img src="@images/search.png" />查询</button></div></div></div><div class="fixedTab noUnfold" v-if="!isUnfold"><divv-for="item of modelSortList":key="item.name"@click="gotoView(item.id)">{{ item.shortName }}</div><div style="font-size:25px" @click="isUnfold = !isUnfold"><i class="el-icon-arrow-right"></i></div></div><div class="fixedTab unfold" v-else><div v-for="(item, index) of modelSortList" :key="item.shortName"><span @click="gotoView(item.id)">{{ item.name }}</span><template v-if="setSortNow">&nbsp;<iv-if="index != modelSortList.length - 1"@click="setIt('下移', index)"class="el-icon-bottom"></i><iv-if="index != 0"@click="setIt('上移', index)"class="el-icon-top"></i>&emsp;</template></div><div style="font-size:25px"><i @click="isUnfold = !isUnfold" class="el-icon-arrow-left"></i><buttonv-if="!setSortNow"class="blue"style="height:30px"@click="setSortNow = true">排序设置</button><buttonv-elseclass="blue"style="height:30px"@click="setSortNow = false,setSortList()">保存</button></div></div><!-- <div class="tab"><div><span:class="type == 'Table' ? 'checked' : ''"@click="type = 'Table'">统计报表</span>|&emsp;<span:class="type == 'Chart' ? 'checked' : ''"@click="type = 'Chart'">图表分析</span></div></div> --><template v-for="item of modelSortList"><component:createTime="createTime":key="item.id + timer":is="'Chart' + item.id":ref="'Chart' + item.id"></component></template><!--<div v-show="type == 'Chart'"><hint-set-chart :createTime="createTime" /></div> --></div></div></div>
</template><script>
// import checkMixin from "@/js/checkMisIn.js";
// import hintSetChart from "./hintSetChart.vue";
import { removeEmptyChildren, treeToList } from "@/js/common.js";
import Component from "../../common/cwDialog/src/component.vue";
import Chart1 from "./hintSetChild/chart1.vue";
import Chart2 from "./hintSetChild/chart2.vue";
import Chart3 from "./hintSetChild/chart3.vue";
import Chart4 from "./hintSetChild/chart4.vue";
import Chart5 from "./hintSetChild/chart5.vue";
import Chart6 from "./hintSetChild/chart6.vue";
import Chart7 from "./hintSetChild/chart7.vue";
const month = new Date().getMonth() + 1;
export default {components: {// hintSetChart,Component,Chart1,Chart2,Chart3,Chart4,Chart5,Chart6,Chart7},// mixins: [checkMixin],data() {return {setSortNow:false,timer: "",limitObj: {},limitTimeStr: "",modelSortList: [],isUnfold: false,sendOrgId: "",organization: [], //组织机构树organizationList: [], //组织机构列表pickerOptionsEnd: {disabledDate: time => {// if (this.timeRangeStart) {//   return (//     time.getTime() > Date.now() - 8.64e6 ||//     //结束日期要在选择的开始日期之后,小于开始时间的日期不能选//     time.getTime() < new Date(this.timeRangeStart).getTime()//   );// }return (time.getTime() > Date.now() - 8.64e6 ||time.getTime() < new Date(this.limitTimeStr).getTime()); //今天及之前}},timeRangeStart: "",timeRangeEnd: "",rangeSet: "",timeRange: "", //默认当年当季当月defaultObj: {value: "",label: "",children: [{value: "1",label: "第一季度",children: [{value: "1",label: "1月"},{value: "2",label: "2月"},{value: "3",label: "3月"}]},{value: "2",label: "第二季度",children: [{value: "4",label: "4月"},{value: "5",label: "5月"},{value: "6",label: "6月"}]},{value: "3",label: "第三季度",children: [{value: "7",label: "7月"},{value: "8",label: "8月"},{value: "9",label: "9月"}]},{value: "4",label: "第四季度",children: [{value: "10",label: "10月"},{value: "11",label: "11月"},{value: "12",label: "12月"}]}]},timeOption: [],type: "Table",sortObj: {},createTime:new Date().getFullYear() + (month < 10 ? "-0" + month : "-" + month),expireTimeOption: {disabledDate(time) {return time.getTime() > Date.now() - 8.64e6; //如果没有后面的-8.64e6就是不可以选择今天的}},//旧importlogShow: false,header: {Authorization: localStorage.getItem("header")},editBtnFlag: false,loginRole: JSON.parse(localStorage.getItem("loginUl")),isRole: false, //打开岗位组loading: true,missionList: [],cur: 1, //分页all: 0,rows: 15, //条数totalCount: 0, //总条数list: {},//searchVal: "", //搜索gridData: [],options: "", //地域value: "",optionsUnit: "", //单位名称valueStation: "",optionsStation: [],valueUnit: "",optionsSubordinate: "", //下级单位valueSubordinate: "",checked: false, //全选框状态checkeds: false,isHint: false, //删除deleteId: "",item: {name: "确定删除选中的数据吗?"},saveLoading: false,tradeSetting: {},editSHow: false,addressId: "",orgId: "",deleteIds: "",editList: {},addListsj: "",uploadLoading: false,addxz: "",orderBy: "create_time",depList: [],orgNewName: "",depNewId: "",createdDep: false,createdDepNameText: "",newUnit: "",departmentList: [],unitXID: "",radio: "",isHidden: false};},watch: {},created() {this.getNowTimeRange();this.getDateDic();this.getModelSortList();},async mounted() {this.setBgStyleNow();this.getLimitTimeInfo();},methods: {setIt(type, index) {switch (type) {case "上移":[this.modelSortList[index], this.modelSortList[index - 1]] = [this.modelSortList[index - 1],this.modelSortList[index]];// this.modelSortList[index - 1].isVisible = false;this.$forceUpdate();break;case "下移":[this.modelSortList[index], this.modelSortList[index + 1]] = [this.modelSortList[index + 1],this.modelSortList[index]];// this.modelSortList[index + 1].isVisible = false;this.$forceUpdate();break;}},gotoView(id) {this.$nextTick(() => {const index = "Chart" + id;if (this.$refs[index][0]) {this.$refs[index][0].$el.scrollIntoView();}});},getLimitTimeInfo() {this.timeOption = [];const year = new Date().getFullYear() + "";this.$http({method: "GET",url: "/cbrc/work/statistics/module/startDate"}).then(res => {this.limitObj = res.data.data;this.limitTimeStr = this.limitObj["时间"];for (var i = this.limitObj["年"] * 1; i <= year * 1; i++) {let obj = this.defaultObj;obj.value = i + "";obj.label = i + "年";obj.children.forEach((a, index) => {if (a.value == this.limitObj["季度"]) {obj.children = obj.children.slice(index, obj.children.length);}a.children.forEach((b, index2) => {if (b.value == this.limitObj["月"]) {a.children = a.children.slice(index2, a.children.length);}});});this.timeOption.push(obj);}console.log("this.timeOption :>> ", this.timeOption);});this.$forceUpdate();},getModelSortList() {this.$http({method: "GET",url: "/cbrc/work/statistics/moduleSort/query?code=" + 1}).then(res => {this.modelSortList = res.data.data;});},async setSortList(){this.modelSortList.forEach((i,index)=>{i.sortNum=this.modelSortList.length-index;})console.log('this.modelSortList :>> ', this.modelSortList);await this.$http({method: "POST",url: "/cbrc/work/statistics/moduleSort/save",data: this.modelSortList}).then(res => {if (res && res.data) {if(res.data.code==200){this.$message.success('保存成功');}else{this.$message.warning('保存失败');}}})},getDateDic() {this.$http({method: "GET",url: "/cbrc/user_center/organization/query/children?levelNum=" + 4}).then(res => {this.organization = res.data.data;if (this.organization) {this.organizationList = treeToList(this.organization);removeEmptyChildren(this.organization);this.$forceUpdate();}});},getNowTimeRange() {//获取当前年const year = new Date().getFullYear() + "";// 获取当前季度:var currMonth = new Date().getMonth() + 1;var currQuarter =Math.floor(currMonth % 3 == 0 ? currMonth / 3 : currMonth / 3 + 1) + "";// const info = {//   1: "第一季度",//   2: "第二季度",//   3: "第三季度",//   4: "第四季度"// };// const quarter = info[currQuarter];//获取当前月const monthNum = new Date().getMonth() + 1;const nowMonth = monthNum + "";this.timeRange = [year, currQuarter, nowMonth];},setBgStyleNow() {const that = this;if (this.missionList && this.missionList.length > 0) {this.$nextTick(() => {that.missionList.forEach((item, index) => {if (index % 2 !== 0) {that.$refs["setBgStyle" + index][0].style.backgroundColor ="#f8f8f8";}});});}},//搜索search() {if (this.timeRange && this.timeRange.length) {// if (this.timeRange.length < 2) {//   return this.$message.warning("请选择季度");// }this.timeRangeStart = "";this.timeRangeEnd = "";} else {if (!this.timeRangeStart != !this.timeRangeEnd) {if (!this.timeRangeStart) {return this.$message.warning("请选择开始日期");} else {return this.$message.warning("请选择结束日期");}}}this.timer = new Date().getTime();}}
};
</script>
<style lang="less" scoped>
.commonStyle() {cursor: pointer;min-width: 80px;color: #fff;font-size: 14px;border-radius: 6px !important;
}
.col {display: inline !important;
}
.blue {.commonStyle;
}
.blues {height: 38px;.commonStyle();
}.green {float: right !important;
}
.fl {width: 100% !important;margin: 10px 0 !important;
}
.popRed {color: red;
}
.el-cascader {width: 100%;
}
.extractDataMaintenanceSearch .odd .fl button {margin-bottom: 0px;
}
.lead {position: relative;img {position: absolute;width: 25px;bottom: 25px;cursor: pointer;}
}
.styleSet {.item {height: 40px;line-height: 40px;display: flex;justify-content: space-between;.el-input,.el-select,.el-cascader,.col-1-1 {width: 80%;}}
}
.buttonStyle {cursor: pointer;display: inline-block;width: 20px;height: 20px;margin: 0px 5px;margin-top: 10px;vertical-align: middle;cursor: pointer;background-size: contain;
}
.item {margin-top: 4px;padding-top: 4px;
}
.order {vertical-align: middle;cursor: pointer;width: 18px;
}
.tab {margin-top: 20px;margin-bottom: 20px;padding-left: 20px;font-size: 16px;display: flex;align-items: center;justify-content: flex-end;span {margin-right: 20px;cursor: pointer;}.checked {font-weight: bold;color: var(--mainColor);}
}
.fixedTab {z-index: 1000;position: fixed;top: 350px;background: #fff;left: 40px;border-radius: 10px;font-size: 16px;line-height: 30px;border: 1px solid var(--mainColor);text-align: center;div {padding: 5px;cursor: pointer;text-overflow: ellipsis;white-space: nowrap;overflow: hidden;}
}
.noUnfold {width: 50px;div {&:hover {color: var(--mainColor);}}
}
.unfold {width: 250px;i,span {&:hover {color: var(--mainColor);}}
}
</style>
<style>
@import "common.css";
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/173572.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据结构 / 顺序表操作 / 顺序表尾部删除

1.实现逻辑 只需要把顺序表的长度减1。 2.顺序表尾部删除函数代码 /**顺序表尾部删除* */int delete_tail(sqlist *list) {if(NULLlist || 1is_list_empty(list)){return -1;}list->len--;return 0;}3. 完整代码 #include <string.h> #include <stdlib.h> #in…

Redis Cluster主从模式详解

在软件的架构中&#xff0c;主从模式&#xff08;Master-Slave&#xff09;是使用较多的一种架构。主&#xff08;Master&#xff09;和从&#xff08;Slave&#xff09;分别部署在不同的服务器上&#xff0c;当主节点服务器写入数据时&#xff0c;同时也会将数据同步至从节点服…

图解算法数据结构-LeetBook-树03_层序遍历奇数偶数行方向不同

一棵圣诞树记作根节点为 root 的二叉树&#xff0c;节点值为该位置装饰彩灯的颜色编号。请按照如下规则记录彩灯装饰结果&#xff1a; 第一层按照从左到右的顺序记录 除第一层外每一层的记录顺序均与上一层相反。即第一层为从左到右&#xff0c;第二层为从右到左。 示例 1&…

自动化测试-Selenium

一. Selenium介绍 selenium 是用来做web自动化测试的框架,支持各种浏览器,各种,支持各种语言 原理: 二. 元素定位 2.1 XPath 定位 绝对路径: /html/head/title 相对路径以双斜杠开头,常见的相对路径定位有以下几种: <1>相对路径索引: 索引是从1开始的 <2>相…

语音识别学习笔记

目录 开源的语音识别项目 端到端的多说话人语音识别序列化训练方法简介 新一代 Kaldi: Two-pass 实时语音识别 开源的语音识别项目 有哪些语音识别的开源项目&#xff1f; - 知乎 端到端的多说话人语音识别序列化训练方法简介 端到端的多说话人语音识别序列化训练方法简介 …

探索深度学习:从理论到实践的全面指南

探索深度学习&#xff1a;从理论到实践的全面指南 摘要&#xff1a; 本文旨在提供一个关于深度学习的全面指南&#xff0c;带领读者从理论基础到实践应用全方位了解这一技术。我们将介绍深度学习的历史、基本原理、常用算法和应用场景&#xff0c;并通过Python代码示例和Tens…

STM32使用多路PWM注意事项

这是使用CubeMX自动产生的代码&#xff0c;使用TIM2产生了PA0,PA1,PA2,PA3这4路PWM&#xff0c;可以看到里面Pulse是共同使用了一个sConfigOC,如果是需要动态调整Pulse&#xff0c;就需要特别注意。 如果是用来产生呼吸灯&#xff0c;就会把这4个PWM都打乱&#xff0c;我觉得&a…

Go查询Elasticsearch

在 Go 中需要在 Elasticsearch 中执行带有过滤条件的查询时&#xff0c;你可以使用 github.com/olivere/elastic 库的过滤器&#xff08;Filter&#xff09;功能。以下是一个示例代码&#xff0c;展示了如何在 Go 中使用 Elasticsearch 进行带有过滤条件的分页查询&#xff1a;…

【nlp】4.4 Transformer库的使用(管道模式pipline、自动模式auto,具体模型BertModel)

Transformer库的使用 1 了解Transformers库2 Transformers库三层应用结构3 管道方式完成多种NLP任务3.1 文本分类任务3.2 特征提取任务3.3 完型填空任务3.4 阅读理解任务3.5 文本摘要任务3.6 NER任务4 自动模型方式完成多种NLP任务4.1 文本分类任务4.2 特征提取任务4.3 完型填空…

讯飞星火知识库文档问答Web API的使用(二)

上一篇提到过星火spark大模型&#xff0c;现在有更新到3.0&#xff1a; 给ChuanhuChatGPT 配上讯飞星火spark大模型V2.0&#xff08;一&#xff09; 同时又看到有知识库问答的web api&#xff0c;于是就测试了一下。 下一篇是在ChuanhuChatGPT 中单独写一个基于星火知识库的内容…

【Android Jetpack】Navigation的使用

引入 单个Activity嵌套多个Fragment的UI架构模式&#xff0c;非常非常普遍。但是&#xff0c;对Fragment的管理一直是一件比较麻烦的事情。工程师需要通过FragmentManager和FragmentTransaction来管理Fragment之间的切换。页面的切换通常还包括对应用程序App bar的管理、Fragme…

vue3使用element plus树形选择器懒加载回显失败问题。

vue3使用element plus树形选择器懒加载回显时树形数据还未加载完成&#xff0c;回显时显示的的绑定值&#xff0c;不是要显示的名称。 解决1&#xff1a;不使用懒加载&#xff0c;一次性将数据返回完成 解决2&#xff1a;编辑回显时&#xff0c;拿到要显示的中文强制修改显示…

[个人笔记] Zabbix实现Webhook推送markdown文本

系统工程 - 运维篇 第四章 Zabbix实现Webhook推送markdown文本 系统工程 - 运维篇系列文章回顾Zabbix实现Webhook推送markdown文本前言实施步骤 Zabbix新增报警媒介类型Zabbix给用户新增报警媒介Zabbix修改动作的执行操作和恢复操作验证&测试 参考来源 系列文章回顾 第一章…

Linux系统分区和挂载超过2T的硬盘

报错信息&#xff1a;DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT). 转载&#xff1a;Ubuntu(Linux)系统安装扩展硬盘并完成格式化及挂载 - 知乎

微星主板开启VT

微星主板模拟器使用 开启VT 进入BIOS高级-》OC-》CPU特征-》intel 虚拟化技术-》允许

探索RockPlus SECS/GEM平台 - 赋能半导体行业设备互联

SECS/GEM协议&#xff0c;全称为半导体设备通讯标准/通用设备模型&#xff08;SECS/Generic Equipment Model&#xff09;&#xff0c;是一种广泛应用于半导体制造行业的通信协议。它定义了半导体设备与工厂主控系统&#xff08;如MES&#xff09;之间的通信方式&#xff0c;使…

PGP 遇上比特币

重复使用 PGP 密钥作为比特币密钥 介绍 在数字安全领域&#xff0c;密码学在确保数据的完整性和真实性方面发挥着至关重要的作用。 一种广泛使用的加密技术是使用 Pretty Good Privacy (PGP1)。 PGP 为安全通信&#xff08;例如电子邮件、文件传输和数据存储&#xff09;提供加…

解密Spring Cloud微服务调用:如何轻松获取请求目标方的IP和端口

公众号「架构成长指南」&#xff0c;专注于生产实践、云原生、分布式系统、大数据技术分享。 目的 Spring Cloud 线上微服务实例都是2个起步&#xff0c;如果出问题后&#xff0c;在没有ELK等日志分析平台&#xff0c;如何确定调用到了目标服务的那个实例&#xff0c;以此来排…

文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑氢储一体化协同的综合能源系统低碳优化》

这个标题涉及到考虑了多个方面的能源系统优化&#xff0c;其中关键的关键词包括"氢储一体化"、"协同"、"综合能源系统"和"低碳优化"。以下是对这些关键词的解读&#xff1a; 氢储一体化&#xff1a; 氢储存&#xff1a; 指的是氢气的存…

计算机组成原理-Cache替换算法

文章目录 总览随机算法&#xff08;RAND&#xff09;先进先出算法&#xff08;FIFO&#xff09;近期最少使用算法&#xff08;LRU&#xff09;最不经常使用算法&#xff08;LFU&#xff09;总结 总览 随机算法&#xff08;RAND&#xff09; 没有选择性地考虑替换哪一块Cache&a…