webview.vue
827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
<view>
<web-view v-if="src" :src="src" @message="onMessage"></web-view>
</view>
</template>
<script>
import { parse, urlParam } from '@/utils/param';
export default {
data: function() {
return {
src: ''
}
},
onLoad: function(option) {
let query = {};
try {
query = JSON.parse(option.query || {}) || {};
} catch (e) {
query = {};
}
const url = `${option.url}${urlParam(query)}`;
this.src = option.encode ? encodeURI(url) : url;
},
methods: {
onMessage(e) {
const { type, data, message } = e.detail.data[0] || {};
if (type === 'back') {
uni.navigateBack();
} else if (type === 'select') {
uni.$emit('webview-select', data);
// uni.navigateBack();
} else if (type === 'toast') {
uni.showToast({ title: message, icon: 'none' });
}
}
}
}
</script>