html 页面引入 vue 组件之 http-vue-loader.js
一、http-vue-loader.js
http-vue-loader.js 是一个 Vue 单文件组件加载器,可以让我们在传统的 HTML 页面中使用 Vue 单文件组件,而不必依赖 Node.js 等其他构建工具。它内置了 Vue.js 和样式加载器,并能自动解析 Vue 单文件组件中的所有内容,并将其转化为 JavaScript 代码。
ps :注意:httpVueLoader 加载的单文件导出方式不同:module.exports = {},而不是 export default {}
二、示例
这里对了 elementUI 的上传组件做一个封装,使其能可根据业务来配置上传的附件
2.1. vue 组件
<template><div><el-col :span="24" v-for="(template,index) in uploadsTemplates"><el-card style="margin-top: 20px;"><div slot="header" class="clearfix"><el-row style="display: flex;align-items: center;"><el-col :span="20"><span style="font-size: 16px;">{{template.title}}</span></el-col><el-col :span="4" style="text-align: right;"><el-tag v-if="template.required == 'N'" type="info">非必上传</el-tag><el-tag v-if="template.required == 'Y'" type="danger">必须上传</el-tag></el-col></el-row></div><p style="color: #F56C6C;margin-bottom: 5px;">{{template.description}}</p><el-col :span="12" style="padding: 20px 0 "><el-form-item prop="requiredFile"ref="uploadFormItems":rules="template.success||template.required=='N'?[]:[{required: true, message: '请上传必要件', trigger: 'blur'}]"><el-row><el-upload :auto-upload="true"drag:file-list="template.fileList"ref="uploadComponents"name="attachment":on-preview="(file)=>onPreview(file,template)":before-upload="(file)=>onBeforeUpload(file,template)":on-success="(response,file,fileList)=>onUploadSuccess(response,file,fileList,index)":on-remove="(file,fileList)=>onRemoveFile(file,fileList,index,template)":action="uploadsUrl":data="{ywlx:ywlx,applyNo:applyNo,configId:template.configId}"multiple><i class="el-icon-upload"></i><div>将文件拖到此处,或<em>点击上传</em></div><div class="el-upload__tip" slot="tip">{{msg}}</div></el-upload></el-row></el-form-item></el-col></el-card></el-col><div class="demo-image__preview" style="display: none"><el-imagestyle="width: 100px; height: 100px"ref="imagePreview":src="previewSrc":preview-src-list="previewSrcList"></el-image></div></div>
</template><script>
module.exports = {name: "upload-template",props: ['contextPath', 'applyNo', 'ywlx', 'fromedit','msg','beforeUpload'],data() {return {uploadsUrl: this.contextPath + "/system/sysUploadFile/uploadAttachment",//预览图片弹窗imgDialogVisible: false,//预览图片路径previewSrc: '',//预览图片集合previewSrcList: [],// 要件(只是校验用)requiredFile: [],//上传模板uploadsTemplates: [],//上传前钩子onBeforeUpload: this.beforeUpload}},mounted: function () {if(this.onBeforeUpload == null){this.onBeforeUpload = (file,upload)=>{return true;}}else{if (typeof this.onBeforeUpload === 'function') {} else {throw new Error('beforeUpload is not a function');}}// 读取附件模板$.ajax({type: "get",async: false,url: this.contextPath + '/system/sysUploadConfig/getUploadsTemplates',data: {ywlx: this.ywlx},dataType: "json"}).then((response) => {if (response.code == 0) {response.data.forEach(template => {template.success = false;template.fileList = [];});this.uploadsTemplates.push(...response.data);if (this.fromedit) {$.ajax({type: "post",async: false,url: this.contextPath + "/system/sysUploadFile/getFilesByApplyNo",dataType: "json",data: {ywlx:this.ywlx,applyNo: this.applyNo}}).then((response) => {if (response.code == 0) {response.data.forEach(attachemnt => {this.uploadsTemplates.forEach(template => {if (attachemnt.configId === template.configId) {template.fileList.push(attachemnt);template.success = true;}})});} else {this.$message({showClose: true,message: response.msg,type: 'error',offset: 200,duration: 10000});console.log("error:");console.log(response);}});}} else {this.$message({showClose: true,message: response.msg,type: 'error',offset: 200,duration: 10000});console.log("error:");console.log(response);}});},methods: {//预览图片onPreview: function (file, template) {this.previewSrc = this.contextPath+(file.url?file.url:file.response.data.url);template.fileList.forEach((file)=>{this.previewSrcList.push(this.contextPath+(file.url?file.url:file.response.data.url));});console.log(this.previewSrc)console.log(this.previewSrcList)this.$refs.imagePreview.clickHandler();},//文件上传成功的回调onUploadSuccess: function (response, file, fileList, index) {console.log('上传成功需要操作请增加事件:upload-success')if (response.code == 0) {// 把要件列表中的当前这个要件的success置为truethis.uploadsTemplates[index].success = true;this.uploadsTemplates[index].fileList = fileList;}else {this.$message({showClose: true,message: response.msg,type: 'error',offset: 200,duration: 2000});//删除控件里某个文件fileList.splice(fileList.indexOf(file),1);}this.$emit('upload-success',response)//清除控件里所有文件// this.$refs.uploadComponents[index].clearFiles();},//移除某个文件onRemoveFile: function (file, fileList, index, upload) {//调用远程移除附件,传递file.fileId$.ajax({url: this.contextPath + '/system/sysUploadFile/removeAttachment',method: 'post',async: false,data: {fileId: file.fileId?file.fileId:file.response.data.fileId}}).then((response) => {if (response.code == 0) {this.uploadsTemplates[index].fileList = fileList;// 如果已经全部移除,加上校验if(fileList.length===0){this.uploadsTemplates[index].success = false;}} else {console.log("error message:");console.log(response.data);this.$message({showClose: true,message: response.msg,type: 'error',offset: 200,duration: 2000});}});},},
}
</script><style scoped>.el-upload__input{display: none;}
</style>
2.2. html 页面
页面中添加 http-vue-loader.js 后添加组件两种方式
方式一:
// 使用httpVueLoader
Vue.use(httpVueLoader);
var vm = new Vue({el: "#upload-test-form",components: {// 将组建加入组建库'upload-template': 'url:'+ctx+'components/upload-template.vue',},data: {ctx:ctx,fromEdit:true,applyForm: {ywlx:"ywlx1",applyNo:"123456789",},},
});
方式二:
var vm = new Vue({el: "#upload-test-form",components: {// 将组建加入组建库'upload-template': httpVueLoader(ctx+'components/upload-template.vue'),},data: {ctx:ctx,applyForm: {ywlx:"ywlx1",applyNo:"123456789",},},});
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head><th:block th:include="include :: header('新增上传文件信息')" /><th:block th:include="include :: element-ui('新增上传文件信息')" />
</head>
<body class="white-bg"><div class="wrapper wrapper-content animated fadeInRight ibox-content" id="upload-test-form"><div class="row"><el-form ref="uploadForm" id="uploadForm" :model="applyForm"><upload-template :apply-no="applyForm.applyNo":context-path="ctx":before-upload="beforeUpload"@upload-success="uploadSuccess"ywlx="ywlx1"></upload-template></el-form></div></div><th:block th:include="include :: footer" /><th:block th:include="include :: element-ui-js" /><script th:src="@{/lib/http-vue-loader.js}"></script><script th:inline="javascript">var prefix = ctx + "system/sysUploadFile";var vm = new Vue({el: "#upload-test-form",components: {// 将组建加入组建库'upload-template': httpVueLoader(ctx+'components/upload-template.vue'),},data: {ctx:ctx,applyForm: {ywlx:"ywlx1",applyNo:"123456789",},},methods: {beforeUpload: function(file,template){console.log("上传前操作")console.log(file)console.log(template)//返回 true,继续上传,返回false,终止上传return false;},uploadSuccess: function(file){console.log("上传成功操作")console.log(file)}}});function submitHandler() {vm.$refs.uploadForm.validate((valid) => {if (valid) {alert('文件验证通过!');} else {alert('文件验证失败!');}});}</script>
</body>
</html>
3.3. 效果
业务类型上传文件配置

业务上传附件页面

保存的文件

总结:
通过 http-vue-loader.js,我们可以在普通的 HTML 页面中使用 Vue 单文件组件来实现前端开发的快速迭代。在使用 http-vue-loader.js 时,我们需要引入 Vue.js 和 http-vue-loader.js,并使用 httpVueLoader () 方法加载 Vue 单文件组件,并将其实例化为 Vue 对象。
相关文章:
html 页面引入 vue 组件之 http-vue-loader.js
一、http-vue-loader.js http-vue-loader.js 是一个 Vue 单文件组件加载器,可以让我们在传统的 HTML 页面中使用 Vue 单文件组件,而不必依赖 Node.js 等其他构建工具。它内置了 Vue.js 和样式加载器,并能自动解析 Vue 单文件组件中的所有内容…...
html+css网页设计 旅行 蜘蛛旅行社3个页面
htmlcss网页设计 旅行 蜘蛛旅行社3个页面 网页作品代码简单,可使用任意HTML辑软件(如:Dreamweaver、HBuilder、Vscode 、Sublime 、Webstorm、Text 、Notepad 等任意html编辑软件进行运行及修改编辑等操作)。 获取源码 1&#…...
考拉悠然产品发布会丨以悠然远智全模态AI应用平台探索AI行业应用
9月6日,成都市大模型新技术新成果发布暨供需对接系列活动——考拉悠然专场,在成都市高新区菁蓉汇盛大举行。考拉悠然重磅发布了悠然远智丨全模态AI应用平台,并精彩展示了交通大模型应用——智析快处等最新的AI产品和技术成果。 在四川省科学…...
LLM大模型学习:揭秘LLM应用构建:探究文本加载器的必要性及在LangChain中的运用
构建 LLM 应用为什么需要文本加载器,langchain 中如何使用文本加载器? 在不同的应用场景中需要使用不同的文本内容作为内容的载体,针对不同的类型的文本,langchain 提供了多种文本加载器来帮助我们快速的将文本切片,从…...
Flutter函数
在Dart中,函数为 一等公民,可以作为参数对象传递,也可以作为返回值返回。 函数定义 // 返回值 (可以不写返回值,但建议写)、函数名、参数列表 showMessage(String message) {//函数体print(message); }void showMessage(String m…...
P3565 [POI2014] HOT-Hotels
~~~~~ P3565 [POI2014] HOT-Hotels ~~~~~ 总题单链接 思路 ~~~~~ 设 g [ u ] [ i ] g[u][i] g[u][i] 表示在 u u u 的子树内,距离 u u u 为 i i i 的点的个数。 ~~~~~ 设 d p [ u ] [ i ] dp[u][i] dp[u][i] 表示: u u u 的子树内存在两个点 x , …...
设计模式 | 单例模式
定义 单例设计模式(Singleton Pattern)是一种创建型设计模式,它确保一个类只有一个实例,并提供一个全局访问点来获取该实例。这种模式常用于需要控制对某些资源的访问的场景,例如数据库连接、日志记录等。 单例模式涉…...
Web安全之CSRF攻击详解与防护
在互联网应用中,安全性问题是开发者必须时刻关注的核心内容之一。跨站请求伪造(Cross-Site Request Forgery, CSRF),是一种常见的Web安全漏洞。通过CSRF攻击,黑客可以冒用受害者的身份,发送恶意请求&#x…...
IDEA运行Java程序提示“java: 警告: 源发行版 11 需要目标发行版 11”
遇到这个提示一般是在pom.xml中已经指定了构建的Java版本环境是11例如(此时添加了build插件的情况下虽然不能直接运行代码但是maven是可以正常打包构建): <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><…...
车载测试| 汽车的五域架构 (含线控技术知识)
汽车的五域架构是一种将汽车电子控制系统按照功能进行划分的架构模式,主要包括动力域、底盘域、座舱域、自动驾驶域和车身域。(汽车三域架构通常是指将汽车电子系统划分为三个主要领域:动力域、底盘域和智能座舱域(或车身舒适域&a…...
【Linux】gcc/g++ 、make/Makefile、git、gdb 的使用
目录 1. Linux编译器-gcc/g1.1 编译器gcc/g的工作步骤1.2 函数库1.2.1 函数库的作用及分类1.2.2 动态链接和静态链接1.2.3 动态库和静态库的优缺点 1.3 gcc选项 2. Linux项目自动化构建工具-make/Makefile2.1 .PHONY2.2 尝试编写进度条程序 3. git3.1 安装 git3.2 下载项目到本…...
Elastic Stack--ES的DSL语句查询
前言:本博客仅作记录学习使用,部分图片出自网络,如有侵犯您的权益,请联系删除 学习B站博主教程笔记: 最新版适合自学的ElasticStack全套视频(Elk零基础入门到精通教程)Linux运维必备—Elastic…...
ARM基础知识---CPU---处理器
目录 一、ARM架构 1.1.RAM---随机存储器 1.2.ROM---只读存储器 1.3.flash---闪存存储器 1.4.时钟(振晶) 1.5.复位 二、CPU---ARM920T 2.1.R0~R12---通用寄存器 2.2.PC程序计数器 2.3.LR连接寄存器 2.4.SP栈指针寄存器 2.5.CPSR当前程序状态寄存…...
将星 x17 安装ubuntu 20.04 双系统
准备工作,包含关闭快速启动,关闭Secret Boot 1.进入控制面板选择小图标,找到电源选项 2.点击更改当前不可用的设置,关闭快速启动 3.开机启动时快速按F2,进入BIOS 4.选择Setup Utiltity,选择Security&#…...
E31.【C语言】练习:指针运算习题集(上)
Exercise 1 求下列代码的运行结果 #include <stdio.h> int main() {int a[5] { 1, 2, 3, 4, 5 };int* ptr (int*)(&a 1);printf("%d",*(ptr - 1));return 0; } 答案速查: 分析: Exercise 2 求下列代码的运行结果 //在x86环境下 //假设结…...
git分支的管理
分支管理是 Git 版本控制系统中的一个核心功能,它涉及如何创建、管理、合并和删除分支,以便在团队协作和开发过程中更有效地组织代码。以下是分支管理中的一些关键概念和实践: 1. 分支的创建 创建新分支:在开发新功能、修复 bug…...
对于消息队列的一些思考
如何保证消息不被重复消费 唯一ID:你提到的通过唯一ID解决重复消费问题非常重要。这通常通过业务系统引入唯一消息ID(如UUID)来实现。在消费端,先检查消息ID是否已经被处理,未处理过的才进行处理,确保幂等…...
IM即时通讯软件-WorkPlus私有化部署的局域网即时通讯工具
随着企业对通讯安全和数据掌控的需求不断增加,许多企业开始选择私有化部署的即时通讯工具,以在内部局域网环境中实现安全、高效的沟通与协作。IM-WorkPlus作为一款受欢迎的即时通讯软件,提供了私有化部署的选项,使企业能够在自己的…...
AI大模型的饕餮盛宴,系统学习大模型技术,你想要的书都在这里了
AI大模型的饕餮盛宴,系统学习大模型技术,你想要的书都在这里了 要说现在最热门的技术,可谓非大模型莫属!不少小伙伴都想要学习大模型技术,转战AI领域,以适应未来的大趋势,寻求更有前景的发展~~…...
支付宝开放平台-开发者社区——AI 日报「9 月 9 日」
1 离开 OpenAl 后,llya 拿了10亿美金对抗 Al 作恶 极窖公园 丨阅读原文 lya Sutskever, OpenAl的前联合创始人,成立了SS1 (Safe Superintelligence),旨在构建安全的Al模型。SSl获得了10亿美元的融资,估值达到50亿美元ÿ…...
【昇腾实战】MindIE框架下DeepSeek-R1模型部署与性能调优指南
1. 昇腾环境准备与驱动安装 拿到昇腾服务器后,第一件事就是搭建基础运行环境。我遇到过不少开发者卡在驱动安装环节,其实只要注意几个关键点就能避坑。首先到华为昇腾官网下载对应版本的驱动和固件包,这里有个细节:一定要核对服务…...
YOLOv11检测头架构演进与工程实现剖析
1. YOLOv11检测头架构演进解析 目标检测领域近年来发展迅猛,YOLO系列作为其中的佼佼者,每次迭代都带来显著突破。YOLOv11的检测头设计堪称该系列迄今为止最精妙的架构创新,它彻底重构了传统检测头的任务处理方式。我曾在多个工业项目中尝试过…...
别再只用Axios了!Vue3项目里用MinIO实现文件上传的保姆级教程(含.env配置避坑)
别再只用Axios了!Vue3项目里用MinIO实现文件上传的保姆级教程(含.env配置避坑) 当你在Vue3项目中需要实现文件上传功能时,第一反应是不是封装一个Axios请求,把文件发送到后端服务器处理?这种传统方案虽然可…...
原神帧率解锁终极指南:3步轻松突破60FPS限制,享受极致流畅体验
原神帧率解锁终极指南:3步轻松突破60FPS限制,享受极致流畅体验 【免费下载链接】genshin-fps-unlock unlocks the 60 fps cap 项目地址: https://gitcode.com/gh_mirrors/ge/genshin-fps-unlock 还在为原神60帧限制而苦恼吗?高端显卡却…...
Dockle在大型项目中的应用:多镜像批量扫描与报告生成完整指南
Dockle在大型项目中的应用:多镜像批量扫描与报告生成完整指南 【免费下载链接】dockle Container Image Linter for Security, Helping build the Best-Practice Docker Image, Easy to start 项目地址: https://gitcode.com/gh_mirrors/do/dockle Dockle是一…...
OrigamiSimulator:3分钟上手实时折纸模拟的完整指南
OrigamiSimulator:3分钟上手实时折纸模拟的完整指南 【免费下载链接】OrigamiSimulator Realtime WebGL origami simulator 项目地址: https://gitcode.com/gh_mirrors/or/OrigamiSimulator 你是否曾经好奇复杂的折纸结构是如何从平面纸张变为立体形态的&…...
Cursor Pro免费激活指南:3步解锁AI编程工具的完整功能
Cursor Pro免费激活指南:3步解锁AI编程工具的完整功能 【免费下载链接】cursor-free-vip [Support 0.45](Multi Language 多语言)自动注册 Cursor Ai ,自动重置机器ID , 免费升级使用Pro 功能: Youve reached your tri…...
揭秘C++多态:动态行为的核心奥秘
C 多态:面向对象的动态行为核心机制多态性是面向对象编程(OOP)的核心概念之一,它允许对象在运行时根据其实际类型表现出不同的行为。在C中,多态性主要通过虚函数(virtual functions)和继承机制实…...
Path of Building PoE2:零基础掌握流放之路2角色规划工具实战指南
Path of Building PoE2:零基础掌握流放之路2角色规划工具实战指南 【免费下载链接】PathOfBuilding-PoE2 项目地址: https://gitcode.com/GitHub_Trending/pa/PathOfBuilding-PoE2 你是否曾遇到这样的困境:花费数小时规划的角色build,…...
Agent的决策模糊
文章目录Langchian Agent内部记忆:信息过载LLM注意力有限的解释:上下文窗口长度很大,会有这种问题么对比langGraphLangchian Agent内部记忆: 官方 ReAct 内部机制(铁律) LangChain 的 AgentExecutor 在一次 invoke () 内部&#…...
