vue3-sfc-loader 加载远程.vue文件(sfc)案例

news2025/2/28 11:05:35

注意事项

  1. style标签如果增加了lang比如:lang=“scss”,需要提供scss-loader的处理器,这个暂时没研究,我的处理方式是将动态模版的css放在了全局
  2. 打包暂时还没有测试,后面测试了会同步更新

安装vue3-sfc-loader

npm install vue3-sfc-loader

后端vue模版 (sfc案例)

后端我用的是java加Velocity模版引擎(.vm模版)

vm模版引擎位置:
在这里插入图片描述

vm模版

<template>
  <view class="cus-tab theme theme-page">
    <uniForms ref="formRef" :modelValue="formData" validate-trigger="bind">
      <table class="tableCla">
        <colgroup>
          <col style="width: 20px;">
          <col style="width: 70px;">
          <col style="width: 130px;">
          <!-- <col style="width: 70px;"> -->
        </colgroup>
        <thead>
        <tr>
          <th class="slash-wrap" colspan="2">
            <div class="oline">
              <span class="span1">年级</span>
              <span class="span2">姓名</span>
            </div>
          </th>
          <th>高三二班</th>
          <th>异议数据</th>
        </tr>
        </thead>
        <tbody>
        <tr>
          <td colspan="2">身高</td>
          <td>身高</td>
          <td>
            <uniFormsItem name="sga">
              <view class="input-cla theme-flex">
                <uniEasyinput :clearable="false" v-model="formData.sga"
                               placeholder=""></uniEasyinput>
                <text>cm</text>
              </view>
            </uniFormsItem>
          </td>
        </tr>
        <tr>
          <td colspan="2">体重</td>
          <td>88888888</td>
          <td>
            <uniFormsItem name="tz">
              <view class="input-cla theme-flex">
                <uniEasyinput :clearable="false" v-model="formData.tz"
                               placeholder=""></uniEasyinput>
                <text>kg</text>
              </view>
            </uniFormsItem>
          </td>
        </tr>
        <tr>
          <td colspan="1" rowspan="3">眼科检查</td>
          <td>裸眼视力</td>
          <td>das</td>
          <td>
            <view class="theme-flex">
              <view class="input-cla theme-flex">
                <uniFormsItem name="lyz">
                  <view class="input-cla theme-flex">
                    <text>左</text>
                    <uniEasyinput :clearable="false" v-model="formData.lyz"
                                   placeholder=""></uniEasyinput>
                  </view>
                </uniFormsItem>
                <text>/</text>
                <uniFormsItem name="lyy">
                  <view class="input-cla theme-flex">
                    <text>右</text>
                    <uniEasyinput :clearable="false" v-model="formData.lyy"
                                   placeholder=""></uniEasyinput>
                  </view>
                </uniFormsItem>
              </view>
            </view>

          </td>
        </tr>
        <tr>
          <td>矫正视力</td>
          <td>John</td>
          <td>
            <view class="theme-flex">
              <view class="input-cla theme-flex">
                <uniFormsItem name="jzz">
                  <view class="input-cla theme-flex">
                    <text>左</text>
                    <uniEasyinput :clearable="false" v-model="formData.jzz"
                                   placeholder=""></uniEasyinput>
                  </view>
                </uniFormsItem>
                <text>/</text>
                <uniFormsItem name="jzy">
                  <view class="input-cla theme-flex">
                    <text>右</text>
                    <uniEasyinput :clearable="false" v-model="formData.jzy"
                                   placeholder=""></uniEasyinput>
                  </view>
                </uniFormsItem>
              </view>
            </view>
          </td>
        </tr>
        <tr>
          <td>角膜炎</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <wdCheckbox v-model="formData.jmy" shape="square">有异议</wdCheckbox>
            </view>
          </td>
        </tr>
        <tr>
          <td colspan="1" rowspan="4">内科检查</td>
          <td>心脏</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <wdCheckbox v-model="formData.xz" shape="square">有异议</wdCheckbox>
            </view>
          </td>
        </tr>
        <tr>
          <td>肺</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <wdCheckbox v-model="formData.fei" shape="square">有异议</wdCheckbox>
            </view>
          </td>
        </tr>
        <tr>
          <td>肝</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <wdCheckbox v-model="formData.gan" shape="square">有异议</wdCheckbox>
            </view>
          </td>
        </tr>
        <tr>
          <td>脾</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <wdCheckbox v-model="formData.pi" shape="square">有异议</wdCheckbox>
            </view>
          </td>
        </tr>
        <tr>
          <td colspan="1" rowspan="8">外科检查</td>
          <td>头部</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <wdCheckbox v-model="formData.tb" shape="square">有异议</wdCheckbox>
            </view>
          </td>
        </tr>
        <tr>
          <td>颈部</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>甲状腺</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>胸部</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>脊椎</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>四肢</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>皮肤</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>淋巴结</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td colspan="1" rowspan="3">耳鼻喉科</td>
          <td>耳</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>鼻</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td>扁桃体</td>
          <td>John</td>
          <td>
            <view class="input-cla theme-flex">
              <uniEasyinput :clearable="false" v-model="formData.sg" placeholder=""></uniEasyinput>
            </view>
          </td>
        </tr>
        <tr>
          <td colspan="4">
            <view class="input-text-cla">
              <uniFormsItem required name="fkyj" :rules="[{required: true,errorMessage: '请填写反馈意见',}]">
                <view class="theme-flex">
                  <uniEasyinput type="textarea" autoHeight :clearable="false" v-model="formData.fkyj"
                                 placeholder="请输入反馈意见"></uniEasyinput>
                </view>
              </uniFormsItem>
            </view>
          </td>
        </tr>
        </tbody>
      </table>
      <view>
        <view class="tips-clas theme-flex">
          <text>1. 请如实填写,填写完成后保存</text>
          <text>2. 异议数据需机构审核,请耐心等待</text>
        </view>
        <view class="bot-box">
          <wdButton @click="submit">提交审核</wdButton>
        </view>
      </view>
    </uniForms>
  </view>
</template>

<script setup name="Abnormal">
  import { ref, reactive } from 'vue'
  import uniForms from 'uniForms'
  import uniFormsItem from 'uniFormsItem'
  import uniEasyinput from 'uniEasyinput'
  import wdCheckbox from 'wdCheckbox'
  import wdButton from 'wdButton'
  const formRef = ref();
  const formData = reactive({
    sga: '',
    sg: '',
    tz: '',
    lyz: '',
    lyy: '',
    jzz: '',
    jzy: '',
    fkyj: '',
    jmy: false,
    xz: false,
    fei: false,
    gan: false,
    pi: false,
    tb: false,
  });
  const submit = () => {
    formRef.value.validate().then((res) => {
      console.log('表单数据信息:', res);
    }).catch((err) => {
      console.log('表单错误信息:', err);
    })
  };
</script>

<style lang="scss">
  .oline {
    border-top: 50px #c5c5c5 solid;
    width: 0px;
    height: 0px;
    border-left: 90px #ffffff solid;
    position: relative;

  }

  .oline::before {
    position: absolute;
    top: -40px;
    left: -80px;
    width: 80px;
    height: 40px;
    /* background: #fff url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxsaW5lIHgxPSIwIiB5MT0iMCIgeDI9IjEwMCUiIHkyPSIxMDAlIiBzdHJva2U9ImJsYWNrIiBzdHJva2Utd2lkdGg9IjEiLz48L3N2Zz4=) no-repeat 100% center; */
    content: '';
  }

  .span1 {
    font-style: normal;
    display: block;
    position: absolute;
    top: -40px;
    left: -40px;
    width: 35px;
  }

  .span2 {
    font-style: normal;
    display: block;
    position: absolute;
    top: -25px;
    left: -70px;
    width: 55px;
  }

  .top {
    padding: 10px;
    border-bottom: 1px solid #e8e8e8;
  }

  .aColor>a {
    color: rgba(0, 0, 0, 0.65);
  }

  .tableCla {
    width: 100%;
    border: 1px solid #e8e8e8;
    border-collapse: collapse;
  }

  .theadCla>tr>th {
    padding: 10px;
    color: rgba(0, 0, 0, 0.85);
    border: 1px solid #e8e8e8;
    background: #fafafa;
    font-weight: normal;
  }

  tbody>tr>td,
  th {
    text-align: center;
    font-weight: normal;
    color: rgba(0, 0, 0, 0.65);
    /* padding: 15px 10px; */
    border: 1px solid #e8e8e8;
    font-size: 12px;
  }



  tr:nth-child(even) {
    /* background: #effefd; */
  }

  td {
    font-size: 15px;
  }

  .input-cla {
    width: 100%;
    // border: 1px solid #888888;
    height: 30px;
    padding: 10px;
    box-sizing: border-box;
    align-items: center;
    text-align: center;
    justify-content: center;

    :deep(.uni-easyinput__content-input) {
      height: 20px;
      font-size: 14px;
      width: 40px;
    }

    :deep(.uni-easyinput__content) {
      height: 20px;
      font-size: 14px;
      width: 100%;
    }

    :deep(.uni-easyinput) {
      height: 20px;
      font-size: 14px;
      flex: 0;
      width: 40px !important;
    }

    :deep(.uni-input-input) {
      font-size: 11px !important;
    }

    :deep(.uni-easyinput__content-input) {
      height: 20px !important;
    }


  }

  .cus-tab {
    :deep(.uni-forms-item) {
      margin-bottom: 0px !important;
    }
  }

  .input-text-cla {
    padding: 10px 5px;
    padding-bottom: 20px;
    box-sizing: border-box;
  }

  .tips-clas {
    flex-direction: column;
    color: red;
    align-items: flex-start;
    gap: 5px;
    font-size: 14px;
    padding: 10px;
    box-sizing: border-box;
  }

  .bot-box {
    width: 100%;
    padding: 10px;
    padding-top: 5px;
    box-sizing: border-box;
    :deep(.wd-button) {
      width: 90%;
      display: block;
      margin: 0 auto;
    }

  }
</style>

后端处理模版数据

之前写过类似的,就直接拿来用了,传送门

前端案例

前端使用的uniapp+vue3+ts+vite
moduleCache中需要存放你的vm模版中的组件及api差不类似运行时的东西,不然标签是不会被解析的,类似下面中的uni-ui的组件,如果不引入就不会被解析,注意:引入的模版key要与vm模板中的名称一致

<template>
	<!-- <div style=" margin: 0; padding: 0;overflow-y: scroll;"> -->
		<component :is="dynamicComponent" v-if="templateStr"></component>
		<wd-status-tip image="comment" tip="暂无报告数据~" v-else/>
		<Fab ref="fabRef" @selectAr="selectAr" />
	<!-- </div> -->
</template>
<script setup lang="ts" name="CalendarYear">
	import { onLoad } from '@dcloudio/uni-app'
	import uniForms from '@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue'
	import uniFormsItem from '@dcloudio/uni-ui/lib/uni-forms-item/uni-forms-item.vue'
	import uniDataCheckbox from '@dcloudio/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue'
	import uniEasyinput from '@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.vue'
	import { abnormalReport } from '@/api/speExamineResService'
	import { loadModule } from "vue3-sfc-loader/dist/vue3-sfc-loader"
	import wdCheckbox from 'wot-design-uni/components/wd-checkbox/wd-checkbox.vue'
	import wdButton from 'wot-design-uni/components/wd-button/wd-button.vue'
	import * as Vue from 'vue'
	import Fab from '@/components/Fab/index.vue'
	import { compile } from 'sass';
	import useUserStore from "@/store/user";
	const fabRef = ref()
	const proxy = getCurrentInstance()?.proxy
	const dynamicComponent = shallowRef();
	const templateStr = ref('')
	const archiveInfo = computed(() => {
		return useUserStore().getSelectArchive()
	})
	const reportFun = (val : any) => {
		if (!val.archivesId) {
			proxy.$pop.toast('请选择学生')
			nextTick(() => {
				fabRef.value.openAr()
			})
			return;
		}
		console.log('uniForms', uniForms)
		abnormalReport(val.archivesId).then(async (res : any) => {
			console.log(res)
			templateStr.value = res.data
			const options = {
				moduleCache: {
					vue: Vue,
					'uniForms': uniForms,
					'uniFormsItem': uniFormsItem,
					'uniEasyinput': uniEasyinput,
					'wdCheckbox': wdCheckbox,
					'wdButton': wdButton,
					'scss': (source) => {
						console.log('======>source',source)
						return Object.assign(compile(source), { deps: () => [] })
					}
				},
				async getFile() {
					return res.data
				},
				addStyle(textContent) {
					console.log('textContent,', textContent)
					const style = Object.assign(document.createElement('style'), { textContent })
					console.log('style,', style)
					const ref = document.head.getElementsByTagName('style')[0] || null
					document.head.insertBefore(style, ref)
				},
				loader: {
					
				}
			};
			dynamicComponent.value = defineAsyncComponent(() => loadModule(res.fileName || "loader.vue", options))
		})
	}
	const selectAr = async (val : any) => {
		reportFun(val)
	}
	onLoad(() => {
		reportFun(archiveInfo.value)
	})
</script>
<style lang="scss">

</style>

页面效果图

在这里插入图片描述

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

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

相关文章

AIGC的企业级解决方案架构及成本效益分析

AIGC的企业级解决方案架构及成本效益分析 一,企业级解决方案架构 AIGC(人工智能生成内容)的企业级解决方案架构是一个多层次、多维度的复杂系统,旨在帮助企业实现智能化转型和业务创新。以下是总结的企业级AIGC解决方案架构的主要组成部分: 1. 技术架构 企业级AIGC解决方…

NSIS系统制作Windows下的简易的安装程序

一. 前言 NSIS&#xff08;Nullsoft Scriptable Install System&#xff09;是一个专业的开源系统&#xff0c;用于创建 Windows 安装程序。拥有小巧而灵活的特点&#xff0c;受到很多用户的赞赏。 NSIS 基于脚本语言&#xff0c;允许您创建逻辑来处理比较复杂的安装任务。 官…

leetcode-不同路径问题

一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角&#xff08;在下图中标记为 “Finish” &#xff09;。 问总共有多少条不同的路径&#xff1f; 看见题目…

前端开发中的模拟后端与MVVM架构实践[特殊字符][特殊字符][特殊字符]

平时&#xff0c;后端可能不能及时给接口给前端进行数据调用和读取。这时候&#xff0c;前端想到进行模拟后端接口。本文将介绍如何通过vite-plugin-mock插件模拟后端接口&#xff0c;并探讨MVVM架构在前端开发中的应用。此外&#xff0c;我们还将讨论Vue2与Vue3的区别&#xf…

【Tool】沉浸式翻译 DeepLX

效果对比 对比一下四个常用的翻译工具的效果 不难看出只有Deepl算是在讲人话 如何配置 DeepLX 安装沉浸式翻译插件 获取APIKEY 从这获取: https://linux.do/t/topic/111737 配置 参考官方教程: https://linux.do/t/topic/111911

登录认证(3):会话跟踪技术:Session

Session概览 上文提到了&#xff0c;为了在同一个会话中共享数据&#xff08;比如用户的登录状态&#xff09;&#xff0c;我们需要使用会话跟踪技术&#xff0c;Cookie是客户端的会话跟踪技术&#xff0c;是存储在本地浏览器中的。而本文介绍另外一种会话跟踪技术Session&…

2024年博客之星年度评选|第一步——创作影响力评审入围Top300名单 | 博客之星陪跑指南

2024年博客之星年度评选&#xff5c;第一步——创作影响力评审入围Top300名单 | 博客之星陪跑指南 2024年博客之星年度评选正在如火如荼地进行中&#xff01;作为博客圈最具影响力的评选活动之一&#xff0c;今年的评选吸引了众多优秀博主的参与。现在&#xff0c;距离Top300入…

ui文件转py程序的工具

源博客连接&#xff1a; PyCharm中利用外部工具uic转成的py文件&#xff0c;里面全是C代码&#xff0c;并非python类型的代码&#xff0c;导致大量报错。。。_pyside6-uic为什么把ui转为了c-CSDN博客 如果想把ui文件转为py文件&#xff0c;首先设置pycharm的外部工具&#xf…

【喜讯】海云安荣获“数字安全产业贡献奖”

近日&#xff0c;国内领先的数字化领域独立第三方调研咨询机构数世咨询主办的“2025数字安全市场年度大会”在北京成功举办。在此次大会上&#xff0c;海云安的高敏捷信创白盒产品凭借其在AI大模型技术方面的卓越贡献和突出的技术创新能力&#xff0c;荣获了“数字安全产业贡献…

FluentCMS:基于 ASP.NET Core 和 Blazor 技术构建的开源CMS内容管理系统

推荐一个基于 ASP.NET Core 和 Blazor 技术构建的、功能完善的开源CMS内容管理系统。 01 项目简介 FluentCMS 是一个基于强大的 ASP.NET Core 和创新的 Blazor 技术构建的现代内容管理系统&#xff08;CMS&#xff09;。 FluentCMS 设计为快速、灵活且用户友好&#xff0c;它…

Java实现简易银行账户管理系统

目录 1、项目概述 1.1 项目结构 1.2 技术栈 2、核心功能说明 2.1 账户管理 2.2 异常处理体系 3、设计理念解析 3.1 面向对象设计 3.2 关键设计点 4、使用指南 4.1 运行流程 4.2 注意事项 5、扩展建议 5.1增加功能 5.2优化方向 6、主要的功能模块代码说明 6.1exception 6.2main …

深度学习系列75:sql大模型工具vanna

1. 概述 vanna是一个可以将自然语言转为sql的工具。简单的demo如下&#xff1a; !pip install vanna import vanna from vanna.remote import VannaDefault vn VannaDefault(modelchinook, api_keyvanna.get_api_key(my-emailexample.com)) vn.connect_to_sqlite(https://va…

C# 网络协议第三方库Protobuf的使用

为什么要使用二进制数据 通常我们写一个简单的网络通讯软件可能使用的最多的是字符串类型&#xff0c;比较简单&#xff0c;例如发送格式为(head)19|Msg:Heart|100,x,y,z…&#xff0c;在接收端会解析收到的socket数据。 这样通常是完全可行的&#xff0c;但是随着数据量变大&…

网络安全 | 什么是正向代理和反向代理?

关注&#xff1a;CodingTechWork 引言 在现代网络架构中&#xff0c;代理服务器扮演着重要的角色。它们在客户端和服务器之间充当中介&#xff0c;帮助管理、保护和优化数据流。根据代理的工作方向和用途&#xff0c;代理服务器可分为正向代理和反向代理。本文将深入探讨这两种…

Python 预训练:打通视觉与大语言模型应用壁垒——Python预训练视觉和大语言模型

大语言模型是一种由包含数百亿甚至更多参数的深度神经网络构建的语言模型&#xff0c;通常使用自监督学习方法通过大量无标签文本进行训练&#xff0c;是深度学习之后的又一大人工智能技术革命。 大语言模型的发展主要经历了基础模型阶段(2018 年到2021年)、能力探索阶段(2019年…

AIGC视频生成模型:Meta的Emu Video模型

大家好&#xff0c;这里是好评笔记&#xff0c;公主号&#xff1a;Goodnote&#xff0c;专栏文章私信限时Free。本文详细介绍Meta的视频生成模型Emu Video&#xff0c;作为Meta发布的第二款视频生成模型&#xff0c;在视频生成领域发挥关键作用。 &#x1f33a;优质专栏回顾&am…

定位,用最通俗易懂的方法2.1:CRLB实例

二郎就不设置什么VIP可见啥的了&#xff0c;这样大家都能看到。 如果觉得受益&#xff0c;可以给予一些打赏&#xff0c;也算对原创的一些鼓励&#xff0c;谢谢。 钱的用途&#xff1a;1&#xff09;布施给他人&#xff1b;2&#xff09;二郎会有更多空闲时间写教程 起因&…

python学习笔记3-字符串常用的方法

一、判断&#xff08;9个&#xff09;&#xff1a; 二、查找和替换&#xff08;8个&#xff09; 三、⼤⼩写转换&#xff08;5个&#xff09; 四、⽂本对⻬&#xff08;3个&#xff09; 五、去除空⽩字符&#xff08;3个&#xff09; 六、拆分和连接 &#xff08;6个&#xff0…

【FreeRTOS 教程 一】任务结构体及其基础创建使用

目录 一、任务与协程的区别&#xff1a; &#xff08;1&#xff09;任务的特点&#xff1a; &#xff08;2&#xff09;协程的特点&#xff1a; &#xff08;3&#xff09;总结&#xff1a; 二、任务概述 &#xff1a; &#xff08;1&#xff09;任务状态&#xff1a; &…

node.js 07.npm下包慢的问题与nrm的使用

一.npm下包慢 因为npm i 默认从npm官网服务器进行下包,但是npm官网服务器是海外服务器所以响应很慢. 于是我们通过npm下包的时候通常用淘宝镜像进行下包,下面是切换到淘宝镜像地址下包的操作. 二.nrm的使用 nrm是一个管理切换npm下包地址的工具,可以快速切换下包的地址. 安…