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亿美元ÿ…...
7.4.分块查找
一.分块查找的算法思想: 1.实例: 以上述图片的顺序表为例, 该顺序表的数据元素从整体来看是乱序的,但如果把这些数据元素分成一块一块的小区间, 第一个区间[0,1]索引上的数据元素都是小于等于10的, 第二…...
Spark 之 入门讲解详细版(1)
1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室(Algorithms, Machines, and People Lab)开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目,8个月后成为Apache顶级项目,速度之快足见过人之处&…...
【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器
一.自适应梯度算法Adagrad概述 Adagrad(Adaptive Gradient Algorithm)是一种自适应学习率的优化算法,由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率,适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...
循环冗余码校验CRC码 算法步骤+详细实例计算
通信过程:(白话解释) 我们将原始待发送的消息称为 M M M,依据发送接收消息双方约定的生成多项式 G ( x ) G(x) G(x)(意思就是 G ( x ) G(x) G(x) 是已知的)࿰…...
Java如何权衡是使用无序的数组还是有序的数组
在 Java 中,选择有序数组还是无序数组取决于具体场景的性能需求与操作特点。以下是关键权衡因素及决策指南: ⚖️ 核心权衡维度 维度有序数组无序数组查询性能二分查找 O(log n) ✅线性扫描 O(n) ❌插入/删除需移位维护顺序 O(n) ❌直接操作尾部 O(1) ✅内存开销与无序数组相…...
docker 部署发现spring.profiles.active 问题
报错: org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...
Web后端基础(基础知识)
BS架构:Browser/Server,浏览器/服务器架构模式。客户端只需要浏览器,应用程序的逻辑和数据都存储在服务端。 优点:维护方便缺点:体验一般 CS架构:Client/Server,客户端/服务器架构模式。需要单独…...
Vue ③-生命周期 || 脚手架
生命周期 思考:什么时候可以发送初始化渲染请求?(越早越好) 什么时候可以开始操作dom?(至少dom得渲染出来) Vue生命周期: 一个Vue实例从 创建 到 销毁 的整个过程。 生命周期四个…...
深入浅出Diffusion模型:从原理到实践的全方位教程
I. 引言:生成式AI的黎明 – Diffusion模型是什么? 近年来,生成式人工智能(Generative AI)领域取得了爆炸性的进展,模型能够根据简单的文本提示创作出逼真的图像、连贯的文本,乃至更多令人惊叹的…...
ubuntu22.04 安装docker 和docker-compose
首先你要确保没有docker环境或者使用命令删掉docker sudo apt-get remove docker docker-engine docker.io containerd runc安装docker 更新软件环境 sudo apt update sudo apt upgrade下载docker依赖和GPG 密钥 # 依赖 apt-get install ca-certificates curl gnupg lsb-rel…...
