gpt4 book ai didi

javascript - 使用作为参数传递给 url 的 jsonld 数据加载 vue 应用程序

转载 作者:行者123 更新时间:2023-11-30 19:52:09 26 4
gpt4 key购买 nike

假设我有一个 Vue 应用 http://www.example.com/?url=https://example-data.com/activity-sets/example/sample.jsonld .

我希望 vue 应用程序加载页面,jsonld 通过 url 中给定的路径传递,即 https://example-data.com/activity-sets/example/sample.jsonld

想法是:任何人都应该能够将 url 修改为位于世界任何地方的不同 jsonld 数据。我怎样才能做到这一点?

我是 Vue 的新手,不清楚该做什么。

最佳答案

这样的事情相当容易。只需在您的网络服务器的根目录中创建一个 HTML 文档 (index.html) 并添加以下内容:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue Example</title>
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var $_GET=[];
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(a,name,value){$_GET[name]=value;});
new Vue({
el: '#app',
data () {
return {
url: $_GET['url']
}
},
template: '<iframe :src="url"></iframe>'
})
</script>
</body>
</html>

它将从 url 中读取 ?url= 内容并将其作为 iFrame src 插入。

理论上,这可以解决问题。如果你用例如测试这个。 ?url= https://twitter.com/chucknorris您最终将违反“内容安全政策”。大多数站点将以这种方式得到保护,因此您应该根据自己的目的进行测试。

关于javascript - 使用作为参数传递给 url 的 jsonld 数据加载 vue 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54366880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com