我正在使用 Razorpay 进行付款服务。除了结帐页面之外,没有页面使用它。我已将其包含在 nuxt.config.js 文件中。 nuxtjs 中是否可以仅在您可能需要的地方使用脚本?并非在所有页面中。 (我的灯塔分数因此下降)
最佳答案
是的,这是可能的。您可以使用 Local Settings将您的资源包含在 pages/
目录内的 .vue
文件中(此处位于 head 函数中):
<template>
<h1>About page with jQuery and Roboto font</h1>
</template>
<script>
export default {
head () {
return {
script: [
{ src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js' }
],
link: [
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Roboto&display=swap' }
]
}
}
}
</script>
<style scoped>
h1 {
font-family: Roboto, sans-serif;
}
</style>
这里,这个 jQuery
js 文件和 Roboto font
css 只会包含在这个页面中,而不是所有页面中。
关于vue.js - 是否可以仅在需要的地方而不是在 nuxtjs 中的 nuxt.config.js 中实现包含脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62168571/