用户选择文件夹中的PDF文件,返回一个文件路径(file://com.huawei.hmos.filemanager/data/storage/el2/cloud/%E6%A1%88%E4%BE%8B%E8%A6%81%E7%82%B9%E6%80%BB%E7%BB%93.pdf),使用Web组件加载报错。
代码如下:
Text('文件选择器')
.fontSize(16)
.fontWeight(FontWeight.Bold)
.margin({left:20,bottom:20})
.onClick(()=> {
let ops = new picker.DocumentSelectOptions()
let doc = new picker.DocumentViewPicker()
doc.select(ops).then((documentSelectResult: Array<string>) => {
let fileUrl = documentSelectResult[0];
router.pushUrl({
url: 'pages/WebView/index',
params: {
url: fileUrl
}
})
}).catch((err: BusinessError) => {
console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
});
})
}
web组件预览PDF文件直接在组件的src属性传入文件的地址,支持本地和在线的;
参照文档:mixedmode
参照demo: