我已经设置了我的 vue-cli 版本 3 SPA,以便在我的 paths.js 文件中找不到的任何请求将默认为我的 404 视图,如官方文档中所示:
插入到文件底部附近routes.js:
{ // catches 404 errors
path: '*',
name: '404',
component: () => import(/* webpackChunkName: "NotFoundComponent" */ './views/NotFoundComponent.vue'),
},
Run Code Online (Sandbox Code Playgroud)
插入nginx配置文件:
location / {
try_files $uri $uri/ /index.html;
}
Run Code Online (Sandbox Code Playgroud)
这成功地提醒用户他们请求的页面不存在。
我的问题:
我希望错误 404 组件返回 404 响应标头(当前返回 200 状态代码),并将此错误记录到 nginx error.log 文件中。我想这只能通过使用 nginx 配置来实现。有人实现这个目标了吗?
我注意到这个问题在 vue-cli 官方文档的以下页面中得到解决,但它只涉及节点 Express 服务器而不是 nginx:https: //router.vuejs.org/guide/essentials/history-mode。 html#警告
问题:
如何使用 jq 合并多个 JSON 文件。每个合并的对象在最终合并的文件中都必须有自己的键名。
文件 1.json:
{
"shoe": 0,
"temp": "10"
}
Run Code Online (Sandbox Code Playgroud)
file2.json:
{
"num": {
"sock": 0,
"ratio": {
"cat": 100,
"dog": 0
}
},
"hair": "blue"
}
Run Code Online (Sandbox Code Playgroud)
所需的合并输出:
{
"file1": {
"shoe": 0,
"temp": "10"
},
"file2": {
"num": {
"sock": 0,
"ratio": {
"cat": 100,
"dog": 0
}
},
"hair": "blue"
}
}
Run Code Online (Sandbox Code Playgroud)
尝试 1:下面的问题是,如果有意义的话,对象层次结构会被合并:
jq --slurp 'add' file1.json file2.json
Run Code Online (Sandbox Code Playgroud)
尝试 1 输出(不是我想要的):
{
"shoe": 0,
"temp": "10"
"num": { …Run Code Online (Sandbox Code Playgroud) 我编写了以下简单函数,它返回一个最多6位小数的数字:
getFixedDecimalValue(number) {
let fixedDecimalValue = (((number *= 1000000) - (number % 1)) / 1000000);
return fixedDecimalValue;
}
Run Code Online (Sandbox Code Playgroud)
我希望这个函数接受第二个参数,该参数将决定从那时计算多少小数位数然后返回该值(默认为6 dp).
就像是:
getFixedDecimalValue(number, decimalPlaces = 6) {
let fixedDecimalValue = (((number *= decimalPlaces) - (number % 1)) / decimalPlaces);
return fixedDecimalValue;
}
Run Code Online (Sandbox Code Playgroud)
问题:
什么是优雅的转向方法
6 into 1000000
Run Code Online (Sandbox Code Playgroud)
或者号码
3 into 1000
Run Code Online (Sandbox Code Playgroud)
谢谢!