openview.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script>
  6. import helper from "@/libs/helper.js";
  7. export default{
  8. data(){
  9. return {
  10. url:'',
  11. webviewStyles: {
  12. progress: {
  13. color: '#FF3333'
  14. }
  15. },
  16. wv: null
  17. }
  18. },
  19. onLoad:function(option){
  20. console.log(option)
  21. uni.setNavigationBarTitle({
  22. title: option.title
  23. })
  24. var url = decodeURI(option.url);
  25. if(!url || !helper.IsURL(url)){
  26. this.result = "跳转地址错误";
  27. uni.navigateBack({
  28. delta:1,
  29. animationType: 'pop-out',
  30. animationDuration: 200
  31. })
  32. }else{
  33. // #ifdef APP-PLUS
  34. this.wv = plus.webview.create("","custom-webview",{
  35. plusrequire:"none", //禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止
  36. 'uni-app': 'none', //不加载uni-app渲染层框架,避免样式冲突
  37. top:uni.getSystemInfoSync().statusBarHeight + 44 //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的,可以继续降低TOP值
  38. })
  39. this.wv.setStyle({ height:uni.getSystemInfoSync().windowHeight})
  40. this.wv.loadURL(url)
  41. var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
  42. currentWebview.append(this.wv);//一定要append到当前的页面里!!!才能跟随当前页面一起做动画,一起关闭
  43. setTimeout(()=>{this.wv.getStyle()}, 1000);//如果是首页的onload调用时需要延时一下,二级页面无需延时,可直接获取
  44. // #endif
  45. }
  46. }
  47. }
  48. </script>
  49. <style>
  50. </style>