Node.js/nuxt:修订间差异
来自康健生活
< Node.js
| (未显示同一用户的31个中间版本) | |||
| 第1行: | 第1行: | ||
== 引言 == | == 引言 == | ||
== 参数 == | |||
{| class="wikitable" | |||
|- | |||
| [[/target|target]] || [[/modern|modern]] || [[/axios|axios]] | |||
|- | |||
| [[/asyncData|asyncData]] || 示例 || 示例 | |||
|- | |||
| 示例 || 示例 || 示例 | |||
|} | |||
== 内存 == | == 内存 == | ||
<blockquote> | <blockquote> | ||
| 第37行: | 第47行: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| [[/传值|传值]] || | | [[/传值|传值]] || [[/路由|路由]] || [[/跨域|跨域]] || [[/token|token]] || [[/代码打包|代码打包]] | ||
|- | |||
| [[/全局变量|全局变量]] || [[/生命周期|生命周期]] || [[/session|session]] || [[/css module|css module]] | |||
|- | |||
| [[/导入css样式|导入css样式]] || [[/其他|其他]] || [[/骨架屏|骨架屏]] || [[/组件加载方式|组件加载方式]] | |||
|} | |||
== 调试 == | |||
{| class="wikitable" | |||
|- | |||
| [[/debugger|debugger]] || [[/mockjs|mockjs]] || [[/plugin参数|plugin参数]] | |||
|- | |- | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
| 第69行: | 第89行: | ||
*: key值不唯一 | *: key值不唯一 | ||
* Error: Avoided redundant navigation to current location: | * Error: Avoided redundant navigation to current location: | ||
*: | *: 路由重复,<code>this.$router.replace</code> 抛出错误。 | ||
*: <syntaxhighlight lang="javascript"> | *: <syntaxhighlight lang="javascript"> | ||
// this.$router.replace('/search?pageView=SearchAll&q=' + this.searchValue) | |||
this.$router.push('/search?pageView=SearchAll&q=' + this.searchValue)</syntaxhighlight> | this.$router.push('/search?pageView=SearchAll&q=' + this.searchValue)</syntaxhighlight> | ||
*: 或者直接更改文件重写 <code>this.$router.replace</code> 方法。 | |||
*: 在 router.js 文件 | |||
*: <syntaxhighlight lang="javascript"> | |||
/** | |||
* @author kangkk | |||
* @date 2020/7/15 | |||
* @description 禁止 router.replace 方法在路由指向上一次相同地址时抛出 Error: Avoided redundant navigation to current location | |||
*/ | |||
// eslint-disable-next-line no-proto | |||
const originalPush = router.__proto__.replace | |||
// eslint-disable-next-line no-proto | |||
router.__proto__.replace = function replace (location) { | |||
return originalPush.call(this, location).catch(err => err) | |||
}</syntaxhighlight> | |||
* Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. | |||
* getaddrinfo ENOTFOUND | |||
*: DNS 解析问题,我抛出的是 <code>getaddrinfo ENOTFOUND apiv2.chu***.cn</code> 的错误,只需要在本地 hosts 文件夹里将 <code>apiv2.chu***.cn</code> 的解析地址填入即可。 | |||
*: <syntaxhighlight lang="javascript"> | |||
39.***.***.*** apiv2.chu***.cn</syntaxhighlight> | |||
*: 这里需要说明的是,因为项目需求,<code>apiv2.chu***.cn</code> 并不是实际的域名,也就是说它只是一个自定义的字段,需要在 DNS 服务器解析。 | |||
* [Function (anonymous)] | |||
*: 匿名函数 | |||
* Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "whetherJumpUploadInfo" | |||
*: 通过 props 传递给子组件的 whetherJumpUploadInfo,不能在子组件内部修改 props 中的 whetherJumpUploadInfo 值。 | |||
*:<syntaxhighlight lang="html5"> | |||
父组件 | |||
<div :whetherJumpUploadInfo="whetherJumpUploadInfo" @jumpUploadInfo="jumpUploadInfoFn"></div> | |||
子组件 | |||
<template> | |||
... | |||
</template> | |||
<script> | |||
export default { | |||
... | |||
props: { | |||
whetherJumpUploadInfo: { | |||
type: Boolean, | |||
default: () => false | |||
} | |||
}, | |||
methods:{ | |||
uploadOnProgress (){ | |||
// this.whetherJumpUploadInfo = true | |||
this.$emit('jumpUploadInfo'); //通知父组件改变 | |||
} | |||
} | |||
}</syntaxhighlight> | |||
* omputed property "fileList" was assigned to but it has no setter. | |||
*: <syntaxhighlight lang="javascript"> | |||
fileList: { | |||
get () { | |||
return this.$store.state.file.fileList; | |||
}, | |||
set (val) { | |||
this.$store.state.file.fileList = val; | |||
} | |||
} | |||
</syntaxhighlight> | |||
* client.js?06a0:97 Error: [vuex] do not mutate vuex store state outside mutation handlers. | |||
*: 不能直接修改 state,原码: | |||
*: <syntaxhighlight lang="javascript"> | |||
computed: { | |||
fileList: { | |||
get() { | |||
return this.$store.state.file.fileList | |||
}, | |||
set(fileItem) { | |||
this.$store.dispatch('file/addFile', fileItem) | |||
} | |||
} | |||
},</syntaxhighlight> | |||
*: 修改如下 | |||
*: <syntaxhighlight lang="javascript"> | |||
computed: { | |||
fileList: { | |||
get() { | |||
return this.$store.state.file.fileList.slice() | |||
}, | |||
set(fileItem) { | |||
this.$store.dispatch('file/addFile', fileItem) | |||
} | |||
} | |||
},</syntaxhighlight> | |||
* Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "fileList" | |||
:* 原码 | |||
:* <syntaxhighlight lang="javascript"> | |||
mounted() { | |||
Object.assign(this, this.$store.state.file) | |||
this.fetchResourceResTagRecom('cs'); | |||
},</syntaxhighlight> | |||
:* <syntaxhighlight lang="javascript"> | |||
mounted() { | |||
Object.assign({}, this, this.$store.state.file) | |||
this.fetchResourceResTagRecom('cs'); | |||
},</syntaxhighlight> | |||
2020年9月5日 (六) 11:11的最新版本
引言
参数
| target | modern | axios |
| asyncData | 示例 | 示例 |
| 示例 | 示例 | 示例 |
内存
npm install heapdump --save-dev
nuxt.config.js
var headpdump = require('heapdump')
setInterval(function () {
console.log('st headpdump')
headpdump.writeSnapshot(function(err, filename) {
console.log('dump written to', filename)
})
}, 15000)
打开 chrome 浏览器开发者工具 memory 选项卡,点击加载 hepdump。
目录结构
assets // 用于组织未编译的静态资源如LESS、SASS或JavaScript components // 用于自己编写的Vue组件,比如波动组件、日历组件、分页组件 layouts // 布局目录,用于组织应用的布局组件,不可更改 middleware // 用于存放中间件 pages // 用于存放写的页面,我们主要的工作区域 plugins // 用于存放JavaScript插件的地方 static // 用于存放静态资源文件,比如图片 store // 用于组织应用的Vuex 状态管理 .nuxt // Nuxt自动生成,临时的用于编辑的文件,build .editorconfig // 开发工具格式配置 .eslintrc.js // ESLint的配置文件,用于检查代码格式 .gitignore // 配置git不上传的文件 nuxt.config.json // 用于组织Nuxt.js应用的个性化配置,已覆盖默认配置 package-lock.json // npm自动生成,用于帮助package的统一设置的,yarn也有相同的操作 package.json // npm 包管理配置文件
关键词
| 传值 | 路由 | 跨域 | token | 代码打包 |
| 全局变量 | 生命周期 | session | css module | |
| 导入css样式 | 其他 | 骨架屏 | 组件加载方式 |
调试
| debugger | mockjs | plugin参数 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
error
- Renderer resources are not loaded! Please check possible console errors and ensure dis
- 配置项有问题
- ENOSPC: System limit for number of file watchers reached, watch
- 系统监听数上限
- error Unable to resolve path to module '@@/pages/search/navmenu.vue' import/no-unresolved
npm i --save-dev eslint-import-resolver-alias
settings: { 'import/resolver': { alias: { map: [ ['@', './'], ['@@', './'], ['~', './'], ['~~', './'], ], } } },
- Duplicate keys detected: '/search'. This may cause an update error.
- key值不唯一
- Error: Avoided redundant navigation to current location:
- 路由重复,
this.$router.replace抛出错误。 // this.$router.replace('/search?pageView=SearchAll&q=' + this.searchValue) this.$router.push('/search?pageView=SearchAll&q=' + this.searchValue)
- 或者直接更改文件重写
this.$router.replace方法。 - 在 router.js 文件
/** * @author kangkk * @date 2020/7/15 * @description 禁止 router.replace 方法在路由指向上一次相同地址时抛出 Error: Avoided redundant navigation to current location */ // eslint-disable-next-line no-proto const originalPush = router.__proto__.replace // eslint-disable-next-line no-proto router.__proto__.replace = function replace (location) { return originalPush.call(this, location).catch(err => err) }
- 路由重复,
- Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
- getaddrinfo ENOTFOUND
- DNS 解析问题,我抛出的是
getaddrinfo ENOTFOUND apiv2.chu***.cn的错误,只需要在本地 hosts 文件夹里将apiv2.chu***.cn的解析地址填入即可。 39.***.***.*** apiv2.chu***.cn
- 这里需要说明的是,因为项目需求,
apiv2.chu***.cn并不是实际的域名,也就是说它只是一个自定义的字段,需要在 DNS 服务器解析。
- DNS 解析问题,我抛出的是
- [Function (anonymous)]
- 匿名函数
- Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "whetherJumpUploadInfo"
- 通过 props 传递给子组件的 whetherJumpUploadInfo,不能在子组件内部修改 props 中的 whetherJumpUploadInfo 值。
父组件 <div :whetherJumpUploadInfo="whetherJumpUploadInfo" @jumpUploadInfo="jumpUploadInfoFn"></div> 子组件 <template> ... </template> <script> export default { ... props: { whetherJumpUploadInfo: { type: Boolean, default: () => false } }, methods:{ uploadOnProgress (){ // this.whetherJumpUploadInfo = true this.$emit('jumpUploadInfo'); //通知父组件改变 } } }
- omputed property "fileList" was assigned to but it has no setter.
fileList: { get () { return this.$store.state.file.fileList; }, set (val) { this.$store.state.file.fileList = val; } }
- client.js?06a0:97 Error: [vuex] do not mutate vuex store state outside mutation handlers.
- 不能直接修改 state,原码:
computed: { fileList: { get() { return this.$store.state.file.fileList }, set(fileItem) { this.$store.dispatch('file/addFile', fileItem) } } },
- 修改如下
computed: { fileList: { get() { return this.$store.state.file.fileList.slice() }, set(fileItem) { this.$store.dispatch('file/addFile', fileItem) } } },
- Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "fileList"
- 原码
mounted() { Object.assign(this, this.$store.state.file) this.fetchResourceResTagRecom('cs'); },
mounted() { Object.assign({}, this, this.$store.state.file) this.fetchResourceResTagRecom('cs'); },
No categories