webview.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <web-view cache="no-cache" :src="webViewSrc" @message="getMSG"></web-view>
  3. </template>
  4. <script>
  5. import {getToken} from '@/libs/auth.js';
  6. export default {
  7. data() {
  8. return {
  9. webViewSrc:""
  10. }
  11. },
  12. onLoad(options) {
  13. this.init(options)
  14. },
  15. methods: {
  16. init(options){
  17. let t=new Date().getTime();
  18. if(options.type==='scan'){
  19. let href=`${this.$h5}/scanApp/#/pages/index/index`
  20. let qrcode=uni.getStorageSync('qrcode')
  21. qrcode=qrcode.split('?')[1]
  22. this.webViewSrc=`${href}?token=${getToken()}&${qrcode}&v=${t}`
  23. uni.setNavigationBarTitle({
  24. title:"扫码操作"
  25. })
  26. }else{
  27. let other=""
  28. for(let key in options){
  29. if(key!=='href'&&key!=='name'){
  30. other+=`${key}=${options[key]}&`
  31. }
  32. }
  33. this.webViewSrc=`${options.href}?token=${getToken()}&${other}v=${t}`
  34. uni.setNavigationBarTitle({
  35. title:`${options.name}`
  36. })
  37. }
  38. },
  39. getMSG(){
  40. }
  41. },
  42. onBackPress(e){
  43. // console.log(e)
  44. }
  45. }
  46. </script>