<template>
  <web-view :src="src" @message="onMessage"></web-view>
</template>

<script>
export default {
  data() {
    return {
      src: ''
    }
  },
  onLoad() {
    const params = this.$params || {};
    const url = params.url;
    let query = '';
    try {
      query = JSON.parse(params.query);
    } catch(e) {
      query = '';
    }
    let src = url;
    if (params.query) {
      src += uni.$u.queryParams(query);
    }
    this.src = src;
  },
  methods: {
    onMessage(e) {
      uni.$emit('webview-message', e.detail.data);
    }
  }
}
</script>
