web-view——微信小程序嵌入H5


 

  web-view 組件是一個可以用來承載網頁的容器,會自動鋪滿整個小程序頁面。個人類型與海外類型的小程序暫不支持使用。

開發環境:angular + 微信小程序



<!-- wxml --> <!-- 指向微信公眾平台首頁的web-view -->
 <web-view src="http://localhost:4200/"></web-view>  
 
        

  在Angular中調用微信小程序JSSDK

  index.html

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Wechath5</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
</head>

<body>
  <app-root></app-root>
</body>
</html>

 

在Angular組件中調用小程序JSSDK提供方法接口

import { Component, OnInit } from '@angular/core';
declare var wx: any;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  info = null;
  ngOnInit() {
    const that = this;

    // 微信接口
    wx.miniProgram.getEnv(function (res) {
      that.info = res.miniprogram;
    });
  }
}

 

 

 小程序向H5傳遞參數的方式  url?id=1

  H5返回小程序並傳遞參數

 wx.miniProgram.redirectTo({
      url: '../index/index?name=word'
    });

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM