NUXT head 配置 script 脚本
链接形式
head:{
script:[{src='xxx.js'}]
}
javascript 脚本直接嵌入
head:{
script:[{
innerHtml:"console.log(`js脚本`)"
}]
}
HOOKS 配置示例
hooks: {
//需要执行的js
'render:route': (url, result) => {
this.$ = cheerio.load(result.html, { decodeEntities: false });
// window.__nuxt__位于body中的第一个script中,
// 移除了body中第一个脚本标签
this.$(`body script`).eq(0).remove();
result.html = this.$.html();
}
}