vue中使用第三方素材:iframe与访问路径

有很多特效素材都是使用js+html+第三方库制作,本身使用常规的html开发方式,类似:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>测试</title>
		<script type="text/javascript" src="Test.js"></script>
	</head>
	<body>
    <div id='myId'>测试</div>
		<script>
			var test = new Test('myId');
		</script>
	</body>
</html>

设有一个canvas特效素材,现在希望将该素材整体导入到Vue中,像使用图片一样来使用该素材。
这样的一堆文件,要导入到Vue中,需要使用iframe。流程为:

  1. 项目根目录/public/ 下创建一个test文件夹,将所有的素材文件复制到这里。
  2. 创建一个vue文件,使用iframe将素材的html导入即可。

vue文件内容为:

<template>
  <div class="test-container">
    <iframe :src="url" width="100%" height="100%" frameborder="0" scrolling="auto" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      url: './test/index.html'
    }
  },
  methods: {
  }
}
</script>

<style lang="scss">
.test-container {
  width: 100%;
  height: 100%;
  position: absolute;
}
</style>

注意引入素材的html时,必须使用./开头,且该路径中不需要包含public
若使用/开头,调试正常,放到生产环境下可能会提示The origin server did not find a current representation for the target resource or is not willing to disclose that one exists
404

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值