(1)localStorage
適用於存儲用戶名、我的信息等小體積的文本javascript
var name = "張三"; localStorage.setItem("my_name",name);
移除css
localStorage.removeItem("my_name");
(2)sqlite-storage
當要保存圖片這種大致積的文件到本地時,localStorage就不夠用了,用storage
用法
1.在終端里加載java
ionic cordova plugin add cordova-sqlite-storage npm install --save @ionic/storage
2.在app.module.ts中配置sql
import { IonicStorageModule } from '@ionic/storage';
在imports中加入IonicStorageModule.forRoot()npm
imports: [
BrowserModule,
HttpClientModule,
HttpModule,
JsonpModule,
IonicModule.forRoot(MyApp,{
backButtonText:'',//按鈕內容 backButtonIcon:'arrow-back',//按鈕圖標樣式 tabsHideOnSubPages:'true', }), IonicStorageModule.forRoot() ],
3.在須要使用的page中引入bash
import { Storage } from '@ionic/storage';
4.在page的構造函數中聲明storageapp
constructor(public navCtrl: NavController,private storage:Storage) { }
5.保存ionic
this.storage.set('name','張三');
6.獲取ide
this.get('name').then((val)=>{ if(val=='張三'){ console.log("成功"); } });