vue 微软插件实现根据第三方网站链接预览word、pd、excelf等文件

18 篇文章 0 订阅
17 篇文章 1 订阅

一开始做的时候没想到会预览不了,报错

File not found
The URL of the original file is not valid or the document is not publicly accessible.
Verify the URL is correct, then contact the document owner.

如下:
在这里插入图片描述
我在微软官网查到:
官网地址:https://learn.microsoft.com/en-us/webappsserver/configure-office-web-apps-for-sharepoint-2013#problem-you-receive-a-file-not-found-the-url-of-the-original-file-is-not-valid-or-the-document-is-not-publicly-accessible-verify-the-url-is-correct-then-contact-the-document-owner-error-when-you-try-to-view-an-office-document-in-office-web-apps-by-using-a-user-generated-url

在这里插入图片描述
但原因就是第三方链接不能公网访问的。。。(复制第三方链接到浏览器,看看能不能打开链接文件的页面,不能打开或者他报错提示就是不能公网访问)

效果图

1、第三方网站的链接

需要在第三方网站设置链接在公网可以访问,一定要是公网可以访问的链接,如果公网不能访问就预览不了!!!我的项目中使用的是阿里云第三方网站

2、关键

fileUrl就是预览的文件地址,实际上跳转到微软来进行预览,我们只是嵌入它的页面
这样就可以实现预览功能了

3、前端完整功能代码

<el-button @click="handlePreview">预览</el-button>
<el-dialog
      title="预览文件"
      :visible.sync="open"
      width="1200px"
      :modal="true"
      :append-to-body="true"
      :close-on-click-modal="false"
      @close="open = false"
    >
      <iframe :src="url" frameborder="0" scrolling-="auto" style="width:100%;height:600px;"></iframe>
      <span slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
        <el-button type="primary" @click="open = false">确 定</el-button>
      </span>
    </el-dialog>
data() {
	return {
		url: '',
		open: false
	}
}
handlePreview() {
	this.open = true
	const url = '第三方网站的链接'
	this.url = `https://view.officeapps.live.com/op/embed.aspx?src=${url}`
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值