web-view 是一個 web 瀏覽器組件,可以用來承載網頁的容器,會自動鋪滿整個頁面
webview 指向網頁的鏈接(小程序僅支持加載網絡網頁)
以使用web-view來預覽PDF為例:
點擊查看代碼
<template>
<view style="width: 100%;" >
<web-view :src="webUrl"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
webUrl:'',
viewerUrl: '/hybrid/html/web/viewer.html',
}
},
onload(options) {
let fileUrl = encodeURIComponent(JSON.stringify("pdf的地址") // encodeURIComponent 函數可把字符串作為 URI 組件進行編碼。
//encodeURIComponent(JSON.stringify(this.billListData[index])
//使用encodeURIComponent以及JSON.stringify()方法對對象進行字符串化和編碼,這樣可以控制url參數的長度
this.webUrl = this.viewerUrl + '?file=' + fileUrl
}
}
</script>