我在 Nuxt.JS 中启动了一个项目,但已经有了 HTML + CSS + JS 的网站。我只需要在 NuxtJS 的设计中包含这些 HTML 即可。
我已经尝试将 css 作为全局范围放入 nuxt.config.js 中,但是这样它将在 SSR 中编译,我不喜欢它。就像在 html 上导入 css、js...
如何将 CSS 和 Javascript 导入到我的页面中?
谢谢
最佳答案
您所要做的就是在页面的默认导出中包含一个 head 方法。
可以详细了解head方法here
<script>
export default {
head () {
return {
script: [
{ src: 'path/to/your/js/file.js' }
],
link: [
{ rel: 'stylesheet', href: 'path/to/your/css/file.css' }
]
}
}
}
</script>
或
您可以像在 html 中使用 style
标记一样包含它们
<style src="path/to/your/css/file.css"><style>
<!-- You can also add "scoped" or "lang='sass'" etc in there -->
关于javascript - 如何在我的代码 nuxtjs 上导入外部 js 和 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53874997/