webview.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="webview">
  3. <web-view :src="url" id="webcon" @message="handleMessage" cache-control="no-cache">
  4. </web-view>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {
  11. url: '',
  12. device_id: '',
  13. accessToken: ''
  14. }
  15. },
  16. onLoad(options) {
  17. this.device_id = options.device_id
  18. this.accessToken = uni.getStorageSync('session_key')
  19. // this.url = "http://192.168.2.86:9090/h52.html?device_id="+ this.device_id + "&accessToken=" + this.accessToken+'&t='+Date.now()
  20. // this.url = "https://wx.hnyfwlw.com/wexin/h52.html?device_id=" + this.device_id + "&accessToken=" + this.accessToken
  21. this.url = "/static/h52.html?device_id=" + this.device_id + "&accessToken=" + this.accessToken+'&t='+Date.now()
  22. // uni.setStorage({
  23. // key: 'obj',
  24. // data: JSON.stringify({
  25. // device_id: this.device_id,
  26. // accessToken: this.accessToken
  27. // })
  28. // })
  29. //设置 webview 界面的状态栏的 title
  30. uni.setNavigationBarTitle({
  31. title: '监控详情'
  32. });
  33. // this.getWebviewPage()
  34. },
  35. methods: {
  36. getWebviewPage(id) {
  37. this.url = "/static/h5.html?device_id=" + this.device_id + "&accessToken=" + this.accessToken+'&t='+Date.now()
  38. // uni.setStorage({
  39. // key: 'obj',
  40. // data: JSON.stringify({
  41. // device_id: this.device_id,
  42. // accessToken: this.accessToken
  43. // })
  44. // })
  45. //设置 webview 界面的状态栏的 title
  46. uni.setNavigationBarTitle({
  47. title: '监控详情'
  48. });
  49. },
  50. handleMessage(evt) {
  51. console.log('接收到的消息:' + JSON.stringify(evt.detail.data));
  52. }
  53. }
  54. }
  55. </script>
  56. <style>
  57. .webview {
  58. width: 100vw;
  59. height: 100vh;
  60. }
  61. </style>