当我导出为生产时,我不明白这些错误npm run build,但当我测试时npm run dev它工作得很好。我使用API 路由getStaticProps并从中获取。getStaticPath
首先当我npm run build
FetchError: invalid json response body at https://main-website-next.vercel.app/api/products reason: Unexpected token T in JSON at position
0
at D:\zummon\Main Website\main-website-next\node_modules\node-fetch\lib\index.js:272:32
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async getStaticPaths (D:\zummon\Main Website\main-website-next\.next\server\pages\product\[slug].js:1324:18)
at async buildStaticPaths (D:\zummon\Main Website\main-website-next\node_modules\next\dist\build\utils.js:16:80)
at async D:\zummon\Main Website\main-website-next\node_modules\next\dist\build\utils.js:26:612
at async D:\zummon\Main Website\main-website-next\node_modules\next\dist\build\tracer.js:1:1441 {
type: 'invalid-json'
}
Run Code Online (Sandbox Code Playgroud)
\pages\product\[slug]
import { assetPrefix } from '../../next.config'
export default function Page(){...}
export const getStaticProps = async ({ params: { …Run Code Online (Sandbox Code Playgroud) 我不确定如何使用事件目标,closest([name="..."])因为我理解closest()在更改输入字段中的值进行计算后应该获取元素,但我得到的元素是null
function calculate(e) {
if (e.target.name == 'qty') {
var elemPrice = e.target.closest('[name="price"]') //***
var elemAmount = e.target.closest('[name="amount"]') //***
console.log(elemPrice)
console.log(elemAmount)
elemAmount.value = elemPrice.value * e.target.value
}
}
document.addEventListener('DOMContentLoaded',function(){
document.getElementsByName('qty').forEach(t => { t.addEventListener('change',calculate) })
})
Run Code Online (Sandbox Code Playgroud)
<table>
<tbody>
<tr class="uk-hidden">
<td>1</td>
<td><input name="price"></td>
<td><input name="qty"></td>
<td><input name="amount"></td>
</tr>
<tr class="uk-hidden">
<td>2</td>
<td><input name="price"></td>
<td><input name="qty"></td>
<td><input name="amount"></td>
</tr>
<tr class="uk-hidden">
<td>3</td>
<td><input name="price"></td>
<td><input name="qty"></td>
<td><input name="amount"></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我试过了
...
var elemPrice = e.target.parentElement.previousElementSibling.lastElementChild …Run Code Online (Sandbox Code Playgroud) 我已经在 GitHub 上有一个项目,我可以根据需要克隆和获取文件。
我正在使用从
得到文件和 .git 文件夹
但是当我通过单击复选标记(提交)推回时,什么也没有发生
我通常手动将文件上传到 GitHub 网站,但我的项目越来越大,所以..
我是否错过了关于提交和推送到 GitHub 的内容?
我跑了。使用 Next.js 时。
npm run dev
(next dev)
Run Code Online (Sandbox Code Playgroud)
并得到这个错误。
ReferenceError: navigator is not defined
at getChromeVersion (D:\zummon\page\node_modules\jest-worker\node_modules\supports-color\browser.js:5:68)
at Object.<anonymous> (D:\zummon\page\node_modules\jest-worker\node_modules\supports-color\browser.js:14:22)
at Module._compile (internal/modules/cjs/loader.js:1144:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
at Module.load (internal/modules/cjs/loader.js:993:32)
at Function.Module._load (internal/modules/cjs/loader.js:892:14)
at Module.require (internal/modules/cjs/loader.js:1033:19)
at require (internal/modules/cjs/helpers.js:72:18)
at _supportsColor (D:\zummon\page\node_modules\jest-worker\build\workers\ChildProcessWorker.js:39:16)
at ChildProcessWorker.initialize (D:\zummon\page\node_modules\jest-worker\build\workers\ChildProcessWorker.js:136:24)
Run Code Online (Sandbox Code Playgroud)
package.json 中的代码
{
"dependencies": {
"@heroicons/react": "^1.0.1",
"@tailwindcss/forms": "^0.3.3",
"@tailwindcss/typography": "^0.4.1",
"gray-matter": "^4.0.3",
"next": "^10.2.3",
"next-mdx-remote": "^3.0.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/react": "^17.0.11",
"autoprefixer": "^10.2.6",
"postcss": "^8.3.5",
"tailwindcss": "^2.2.2",
"typescript": "^4.3.4"
}
} …Run Code Online (Sandbox Code Playgroud) 例如,我有网址。
我想把它们变成字符串。
'about'
'product'
'learn'
Run Code Online (Sandbox Code Playgroud)
我试过了。顺便说一句,我使用Next.js。
import { useRouter } from 'next/router'
const { asPath } = useRouter()
const result = asPath.substring(1).split('?')[0].split('#')[0].split('/')[0]
Run Code Online (Sandbox Code Playgroud)
但是有没有更好的方法来处理这些问题,例如使用RegEx或其他方法?
并且也期待得到喜欢。
'about' or ['about']
'product/roller' or ['product','roller']
'learn/goin' or ['learn','goin']
Run Code Online (Sandbox Code Playgroud)
可能的?