因此,我正在使用 Tailwind CSS 为我的样式使用 NuxtJS 构建一个网站。我正在使用 @nuxtjs/tailwindcss 模块。
问题是我的字体似乎没有在浏览器上加载。font-family正如您在 devtools 屏幕截图中看到的那样,CSS 仍然应用了正确的内容,但浏览器仍然使用 Times New Roman 呈现我的文本。
-- Devtools 截图
我的字体文件是 .ttf 文件,存储/assets/fonts/在我的项目根目录的文件夹中。
我的tailwind.css文件看起来像这样
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@font-face {
font-family: 'Montserrat';
font-weight: 400;
src: url('../fonts/Montserrat-Regular.ttf') format('ttf');
}
@font-face {
font-family: 'Montserrat';
font-weight: 700;
src: url('../fonts/Montserrat-Bold.ttf') format('ttf');
}
@font-face {
font-family: 'Montserrat';
font-weight: 900;
src: url('../fonts/Montserrat-Black.ttf') format('ttf');
}
Run Code Online (Sandbox Code Playgroud)
我tailwind.config.js看起来像这样
module.exports = {
theme: {
fontFamily: {
sans: ['Montserrat'],
serif: ['Montserrat'],
mono: ['Montserrat'],
display: …Run Code Online (Sandbox Code Playgroud) 我来自 SPA / React 世界,正在开发我的第一个 Nuxtjs SSR 应用程序。
当我运行 npm run build 时,我期望创建工件,这些工件可以复制到我的生产环境,然后使用服务器上的节点运行。当我执行 npm run build 时,我在 dist 文件夹中什么也没有得到,但在 ./nuxt/dist 中有两个文件夹:服务器和客户端。
完全不知道如何从那里继续。所有在线帮助似乎都适用于非生产版本,并且存在整个开发文件夹来运行 nuxt start。
如何进行生产部署并使用服务器上的节点运行它
我正在尝试向 nuxt js 项目中的布局之一添加“获取”函数。我正在使用 nuxt 的最新版本(2.14.0)。
当服务器渲染布局时,我在控制台(服务器端)收到此消息:
WARN Cannot stringify arbitrary non-POJOs i
WARN Cannot stringify POJOs with symbolic keys Symbol(Symbol.toStringTag)
Run Code Online (Sandbox Code Playgroud)
当我从布局中删除获取功能时,此消息消失
目前我的 fetch 函数没有做太多事情
export default {
...
fetch () {
console.log('in fetch')
}
...
}
Run Code Online (Sandbox Code Playgroud)
我正在研究这个 WARN 消息的含义,据我所知,这个错误来自 @nuxt/devalue 库。
有谁知道如何调查此 WARN 消息的来源吗?
谢谢!
我发现这篇很棒的文章可以在 Nuxt v2.13 应用程序中正确管理环境变量。我只是尝试实现建议的逻辑,但我遇到了一些问题,我想问你。
我设置 publicRuntimeConfig 和 privateRuntimeConfig 如下。我正在使用 Contentful,因此我必须正确设置 Contentful 令牌才能进行 API 调用。
export default {
// Nuxt target - See https://nuxtjs.org/api/configuration-target
target: 'static',
// Nuxt rendering mode - See https://nuxtjs.org/api/configuration-mode
mode: 'universal',
// Both server and client.
publicRuntimeConfig: {
backendApi: process.env.BACKEND_API_URL
shopUrl: process.env.SHOP_URL
},
// Only available on server using same $config (it overrides publicRuntimeConfig)
privateRuntimeConfig: {
ctfSpaceId: CTF_SPACE_ID,
ctfCdaAccessToken: CTF_CDA_ACCESS_TOKEN,
ctfCpaAccessToken: CTF_CPA_ACCESS_TOKEN,
ctfEnvironment: CTF_ENVIRONMENT
},
Run Code Online (Sandbox Code Playgroud)
在模块导出语句上方,我必须定义 .env 中的数据,因此:
require('dotenv').config()
const {
CTF_SPACE_ID,
CTF_CDA_ACCESS_TOKEN,
CTF_CPA_ACCESS_TOKEN,
CTF_ENVIRONMENT, …Run Code Online (Sandbox Code Playgroud) 我试图在路由之间添加一个如 nuxt.js 文档中所示的加载器,但它不起作用。但我无法在应用程序启动之前添加启动画面。
我的components/loading.vue 中的代码片段
<template>
<div v-if="loading" class="loading-page">
<p>Loading...</p>
</div>
</template>
<script>
export default {
data: () => ({
loading: false
}),
methods: {
start(){
this.loading = true
},
finish(){
this.loading = false
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
在nuxt.js.config
export default {
...
loading: '~/components/loading.vue'
...
}
Run Code Online (Sandbox Code Playgroud) 我想在标签元素内加载网页iframe。
例如:
<iframe src="https://www.google.com/" title="Google"></iframe>
这给了我这个错误:
Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
如何在 Nuxt.js 应用程序(或 Vue.js - 它应该是非常相似的配置)中解决这个问题?我尝试使用 nuxt-helmet,但根据 dosc,我可以使用DENY或SAMEORIGIN,因为ALLOW-FROM的浏览器支持有限。
我与 Cypress 建立了一个 NuxtJS 项目。在我的测试中,我转到应用程序的其中一个页面,例如主页 (/)
describe('Index page', function () {
it('should show index page of app', function () {
cy.visit('/')
cy.get('h1.title').contains('frontend')
})
})
Run Code Online (Sandbox Code Playgroud)
因此,我需要启动我的开发服务器,以便能够构建我的 Nuxt 应用程序 (Vue),然后启动我的 e2e 测试。
问题是,当我启动它时(相当长,至少 15 秒),它不给我控制权,该进程保持活动状态,所以我无法启动我的纱线命令来运行测试。
describe('Index page', function () {
it('should show index page of app', function () {
cy.visit('/')
cy.get('h1.title').contains('frontend')
})
})
Run Code Online (Sandbox Code Playgroud)
结果,我真的不知道服务器正确启动后如何启动测试。
谢谢。
我尝试使用 Nuxt Auth 模块设置谷歌身份验证,但我从谷歌收到以下错误:
Error 400 : invalid_request
Parameter not allowed for this message type: nonce
Run Code Online (Sandbox Code Playgroud)
这是我的配置
Error 400 : invalid_request
Parameter not allowed for this message type: nonce
Run Code Online (Sandbox Code Playgroud)
以及我如何在我的组件中调用 google auth:
// nuxt.config.js
modules: ["@nuxtjs/axios", "@nuxtjs/auth-next"],
auth: {
router: {
middleware: ["auth"],
},
redirect: {
login: "/login",
logout: "/",
callback: false,
home: "/",
},
strategies: {
google: { clientId: "MyClientID", codeChallengeMethod: "" }
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试从这里运行官方演示:https : //github.com/nuxt-community/auth-module/tree/dev/demo 但我遇到了同样的错误。
我试图通过仅在一个特定页面中使用 nuxt 的 head 属性来链接我的 css 文件,如下所示:
head: {
link: [
{rel: 'stylesheet', href: require('~/assets/css/font.css')},
{rel: 'stylesheet', href: require('~/assets/css/style.css')},
]
}Run Code Online (Sandbox Code Playgroud)
执行此操作后,当我加载页面时一切都很好,但我在控制台 GET http://localhost:3000/[object%20Object] net::ERR_ABORTED 404 (Not Found)看到此错误
当我查看源代码时,我发现 CSS 文件是这样链接的:
<link data-n-head="ssr" rel="stylesheet" href="[object Object]">
<link data-n-head="ssr" rel="stylesheet" href="[object Object]">Run Code Online (Sandbox Code Playgroud)
我需要以这种方式导入我的CSS,但我仍然遇到这个问题,我该如何解决这个问题?
我定义了一个 className 来自定义 sweetAlert2,但显然该样式不适用于 sweet 警报。我把班级名称称为一切,但似乎没有任何作用。问题可能出在这个包的主 css 文件上吗?
swal.fire({
title: Welcome,
className: styleTitle
});
Run Code Online (Sandbox Code Playgroud)
CSS
.styleTitle{
font-size: 25px;
}
Run Code Online (Sandbox Code Playgroud) nuxtjs ×10
vue.js ×7
nuxt.js ×5
javascript ×3
css ×2
cypress ×1
e2e-testing ×1
fonts ×1
nuxt-auth ×1
package.json ×1
sweetalert2 ×1
tailwind-css ×1
vuejs2 ×1