[英]Nuxt add dynamic script tag
I am using nuxt.js and I have the following script tag我正在使用 nuxt.js 并且我有以下脚本标签
<script type="text/javascript">
atOptions = {
'key' : 'id',
'format' : 'iframe',
'height' : 60,
'width' : 468,
'params' : {}
};
document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.highperformancedisplayformat.com/id/invoke.js"></scr' + 'ipt>');
</script>
When I was using a simple script tag like this on nuxt.config.js it was working当我在 nuxt.config.js 上使用像这样的简单脚本标签时,它正在工作
script:[
{ src:'//data.profitablegatetocontent.com/c6/4b/7a/id.js'
}]
But since the script tag I have to use is a bit complicated I got confused and any help would be appreciated.但是由于我必须使用的脚本标签有点复杂,我感到很困惑,我们将不胜感激。
vue-meta to the rescue! vue-meta 来拯救!
The alternative way for adding a dynamic script tag is head()
.添加动态脚本标签的另一种方法是
head()
。
For example, in the default layout:例如,在默认布局中:
<script>
export default {
data() {
return {
title: 'Hello World!'
}
},
head() {
return {
title: this.title,
script: [
{
hid: '',
src: '',
defer: true,
type: '',
innerHTML: ,
callback: () => { }
}
],
meta: [
{
hid: 'description',
name: 'description',
content: 'My custom description'
}
]
}
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.