uniapp使用webview将页面转换成图片支持h5、app、小程序

简介: uniapp使用webview将页面转换成图片支持h5、app、小程序

uniapp使用webview将页面转换成图片支持h5、app、小程序

uniapp项目中新建主页和webview页面

index.vue代码

<template>
  <view>
    <!-- 微信小程序要设置src为网络路径 -->
    <web-view src="/hybrid/html/webview.html"></web-view>
  </view>
</template>

webview代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <title>网络网页</title>
    <style type="text/css">
      .btn {
        display: block;
        margin: 20px auto;
        padding: 5px;
        background-color: #007aff;
        border: 0;
        color: #ffffff;
        height: 40px;
        width: 200px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div id="btn-list" style="display: flex;flex-dis;justify-content: center;flex-direction:column">
        <input style="padding:10px;height: 25px;" placeholder="测试" />
        <button class="btn" type="button" data-action="navigateTo">按钮</button>
      </div>
    </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
  <script>
    html2canvas(document.querySelector("#btn-list")).then(canvas => {
      console.log(canvas)
      const dataUrl = canvas.toDataURL()
        console.log(dataUrl)
                  document.body.appendChild(canvas)
    });
    </script>
  </body>
</html>

实现效果


相关文章
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的老孙电子点菜系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的老孙电子点菜系统的详细设计和实现
27 1
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
33 0
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
33 0
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
45 3
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
41 3
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
27 2
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
39 2
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的移动学习平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的移动学习平台的详细设计和实现
33 1
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的童装商城的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的童装商城的详细设计和实现
29 1
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的教师管理系统的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的教师管理系统的详细设计和实现
37 2