uniapp 常用(查看文件)

// 查看文件
export function showfile(url){
    uni.showLoading({
        title:'加载中'
    })
    uni.downloadFile({
        url: url,
        success: function (res) {
            var filePath = res.tempFilePath;
            uni.openDocument({
                filePath: filePath,
                showMenu: true,
                success: function (res) {
                },
                fail: function () {
                  uni.showToast({
                    title: '暂不支持此类型',
                    duration: 2000,
                    icon: "none",
                  });
                },
                complete:function(){
                    uni.hideLoading();
                }
            });
        },
        fail:function(err){
            uni.hideLoading();
            uni.showToast({
              title: '文件打开失败',
              icon: 'error'
            })
        }
    });
}

 

posted on 2024-06-27 14:32  小虾米吖~  阅读(2)  评论(0编辑  收藏  举报