当前位置: 首页 > news >正文

uniapp处理后端返回的html字符串

前言:采用v-html方法处理

1.处理前

<html><head><meta http‐equiv="Content‐Type" content="text/html; charset=UTF-8"></head><body><form ↵<input type="submit" value="立刻提交" style="display:none" >↵</form>↵<script>document.forms[0].submit();</script></body></html>

2.处理后

<form <input type="submit" value="立刻提交" style="display:none" >↵</form>↵<script>document.forms[0].submit();<\/script>

3.跳转页面方法

//传参
uni.setStorageSync("ICBC_GW_V3_HTML",res.result.payUrl)
//跳转 
uni.navigateTo({url:"/subpages/cashier/webView"})

4.被跳转页面

<template><view v-html="htmlContent"></view>
</template><script>
export default {data() {return {htmlContent:""}},onLoad(e) {console.log(e)//获取参数const html=uni.getStorageSync("ICBC_GW_V3_HTML")console.log(html)this.htmlContent=this.processHtml(html)console.log(this.htmlContent)},mounted() {document.forms[0].submit();},methods: {//仅保留body里面的内容processHtml(html) {// 1. 提取标签内的内容const bodyMatch = html.match(/<body>([\s\S]*)<\/body>/i);if (!bodyMatch) return '';let bodyContent = bodyMatch[1];// 2. 转义标签,防止script中断bodyContent = bodyContent.replace(/<\/script>/g, '<\\/script>');return bodyContent;}}
};
</script><style></style>

http://www.lryc.cn/news/575864.html

相关文章:

  • Redis-zset有序集合
  • 什么是DNS缓存投毒?有哪些防御措施?
  • mac 安装python,切换python版本
  • 聚铭网络入选嘶吼《中国网络安全细分领域产品名录》“云平台安全管理”与“态势感知”双领域TOP10
  • 【C++】责任链模式
  • VSCode中创建和生成动态库项目
  • CSS3实现同心圆效果
  • flink同步kafka到paimon,doris加速查询
  • RediSearch高性能全文搜索引擎
  • AI优化SEO关键词精进
  • 基于Redis分布式的限流
  • JavaScript性能优化
  • Feign 实战指南:从 REST 替代到性能优化与最佳实践
  • 【数据结构】B树的介绍及其实现C++
  • 探访成都芯谷金融中心文化科技产业园:解锁城市发展新密码
  • JDY-23蓝牙模块与电脑的连接方式
  • 024 企业客户管理系统技术解析:基于 Spring Boot 的全流程管理平台
  • JdbcUtils的三个版本
  • 3.web逆向之开发者工具调试
  • Spring-图书管理系统
  • 《Effective Python》第十章 健壮性——显式链接异常,让错误追踪更清晰的艺术
  • 电梯控制系统技术解析:从基础原理到PLC应用
  • Stable Diffusion入门-ControlNet 深入理解 第二课:ControlNet模型揭秘与使用技巧
  • 【RabbitMQ】基于Spring Boot + RabbitMQ 完成应用通信
  • .小故事.
  • Mybatis-Plus源代码走读后记
  • 青少年编程与数学 01-012 通用应用软件简介 15 人工智能助手
  • Rust交互式编程环境Jupyter Lab搭建
  • YOLOv8快速入门
  • HarmonyOS NEXT仓颉开发语言实现画板案例