nuxtjs填坑记录
“nuxt”: “^2.14.0”
this relative module was not found
https://github.com/nuxt/nuxt.js/issues/2713
兼容IE低版本浏览器
- 安装
1
npm install babel-polyfill -s
- 引入 polyfill
1
2// plugins/ployfill.js
import 'babel-polyfill'; - 配置config.js
1
2
3
4// nuxt.config.js
plugins: [
{ src: '@/plugins/polyfill' }
] - 跟目录下创建 .babelrc
1
2
3
4
5
6// .babelrc文件
{
"presets": [
"es2015","stage-0","stage-3"
]
}
解决IE9、IE10报错:
报错:
1 |
|
原因:
1 |
|
解决办法:
1 |
|
其它问题问题记录
- Property ‘$axios’ does not exist on type ‘Index’.
- you need to add “@nuxtjs/axios” to the types array here ‘tsconfig.json’
https://axios.nuxtjs.org/setup/#typescript
- IE9 axios response 需特殊处理
- /plugins/axios.js 见 _ie9Response方法
- robots.js
- 开发、测试环境增加robots.txt文件
1
2User-agent: *
Disallow: /
- props.config.js
- 在build前生成props.json全局环境变量(区分开发、测试、正式环境)
- nuxt An error occurred while rendering the page
- nuxt.config.js 修改配置 dev: false // 线上环境改为 process.env.NODE_ENV !== ‘production’
- nuxt.config.js 配置 router.middleware
- 路由更改调用中间件,应用场景:权限校验,重定向等
https://zh.nuxtjs.org/docs/2.x/directory-structure/middleware/#router-middleware
https://zh.nuxtjs.org/docs/2.x/configuration-glossary/configuration-router/#middleware
- This relative module was not found:
- yarn add node-sass sass-loader –dev
- package.json 升级版本 “@nuxt/typescript-runtime”: “^2.0.0”,
- 全局环境变量 props
- nuxt.config.js 修改配置 head
1
2
3
4
5
6
7script: [{
innerHTML: `var props = ${JSON.stringify(props)}`,
type: 'text/javascript',
body: false
}],
// https://vue-meta.nuxtjs.org/api/#dangerouslydisablesanitizers
__dangerouslyDisableSanitizers: ['script']
参考资料
nuxtjs填坑记录
http://example.com/20200817-nuxtjs-0/