You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
891 B
TypeScript
46 lines
891 B
TypeScript
import Taro from "@tarojs/taro";
|
|
|
|
import { Component } from "react";
|
|
import { Block, WebView } from "@tarojs/components";
|
|
|
|
// 打开外部页面使用
|
|
export default class WebViewPage extends Component<any, any> {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
name: "webView",
|
|
url: "",
|
|
};
|
|
}
|
|
$instance = Taro.getCurrentInstance();
|
|
|
|
async onLoad() {}
|
|
componentDidMount() {}
|
|
|
|
componentWillUnmount() {}
|
|
|
|
componentDidShow() {
|
|
this.initData();
|
|
}
|
|
|
|
componentDidHide() {}
|
|
|
|
async initData() {
|
|
let url = this.$instance.router?.params?.url;
|
|
if (!url?.includes("https://") && !url?.includes("http://")) {
|
|
url = "https://" + url;
|
|
}
|
|
console.log("url", url);
|
|
this.setState({ url: url });
|
|
}
|
|
|
|
render() {
|
|
let { url } = this.state;
|
|
return (
|
|
<Block>
|
|
<WebView src={url}></WebView>
|
|
</Block>
|
|
);
|
|
}
|
|
}
|