关于Ionic4项目的浏览器存储不起效的原因追查

1.查看项目的package.json中

有两个依赖环境:正式环境和开发环境

开发环境中,没有存储依赖:"@ionic/storage": "^2.1.3",

2.项目中有标示环境的文件:

// The file contents for the current environment will overwrite these during build.

// The build system defaults to the dev environment which uses `environment.ts`, but if you do

// `ng build --env=prod` then `environment.prod.ts` will be used instead.

// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {

// production: false //这是默认值

production: true

};

/*

* In development mode, to ignore zone related error stack frames such as

* `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can

* import the following file, but please comment it out in production mode

* because it will have performance impact when throw error

*/

// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

3.检查 environment 被谁使用:

在main.ts中: 打印日志是我添加的

import {enableProdMode} from '@angular/core';

import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';

import {AppModule} from './app/app.module';

import {environment} from './environments/environment';

if (environment.production) {

enableProdMode();

console.log('current run mode: PROD'); // 此信息会在浏览器的控制台打印出来!

} else {

console.log('current run mode: DEV');

}

platformBrowserDynamic().bootstrapModule(AppModule)

.catch(err => console.log(err));

4.再次启动项目ionic serve,检查浏览器的存储,发现有写入值:

5.另一种简单的方式将存储依赖也加到开发环境的依赖中就可以了!

 

6.举一反三:以后再有类似不起效的场景,可以检查这里!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值