GitHub地址:github.com/JerryMissTo… ,歡迎關注css
最近在使用ionic作項目,遇到過一些問題,現記錄下來,說不定有緣人會須要它。咱們的App進入就是登陸界面,登錄成功後會進入到底部有若干Tab的主界面。
Platform Version:html
最近更新了一篇V3.10的開發,地址是:ionic V3.10 開發踩坑集錦,假如兩者有衝突,以最新的爲準。android
使用 ionic cordova build android --prod --release 打包文件會更小,啓動更迅速,親測有效ios
使用Android Studio打開生成的工程,在Manifest.xml中設置權限,在個人Mac上遇到沒法進行網絡訪問的狀況,只得另外添加,可是在另外一同事那兒沒有這個問題,打包直接就能夠進行網絡訪問,真是奇怪git
在登陸成功的處理代碼段中添加this.navCtrl.setRoot(TabsPage)
,其中TabsPage
是主界面。一般App打開就是登陸界面,登錄後纔是主界面。咱們在app.component.ts
中設置了root=LoginPage
,因此一進去就是登陸界面,在主界面點擊返回按鈕會退到登陸界面,執行上述代碼後從新設置Root界面就能夠解決。github
在src
目錄下新建icon
文件夾,把字體文件放進去。而後在theme/variables.scss
中後面添加如下內容,注意把相應位置替換成你本身的:web
$iconfont-path: "../assets/icon";
@font-face {
font-family: "iconfont";
src: url('#{$iconfont-path}/iconfont.eot?t=1495679878046'); /* IE9*/
src: url('#{$iconfont-path}/iconfont.eot?t=1495679878046#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('#{$iconfont-path}/iconfont.woff?t=1495679878046') format('woff'), /* chrome, firefox */
url('#{$iconfont-path}/iconfont.ttf?t=1495679878046') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('#{$iconfont-path}/iconfont.svg?t=1495679878046#iconfont') format('svg'); /* iOS 4.1- */
}
.iconfont {
font-family: "iconfont" !important;
font-size: 1.6rem;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.ion-md-customer-home:before,
.ion-ios-customer-home:before,
.ion-ios-customer-home-outline:before,
.ion-md-customer-rank:before,
.ion-ios-customer-rank:before,
.ion-ios-customer-rank-outline:before,
.ion-md-customer-stock:before,
.ion-ios-customer-stock:before,
.ion-ios-customer-stock-outline:before {
@extend .iconfont;
}
.ion-md-customer-home:before { //在這裏自定義你的名字,例如:customer-home,前綴也要加上,與平臺相關
content: "\e60f";
}
.ion-ios-customer-home:before { //選中
content: "\e611";
}
.ion-ios-customer-home-outline:before { //未選中
content: "\e60f";
}
.ion-md-customer-rank:before {
content: "\e60d";
}
.ion-ios-customer-rank:before {
content: "\e60e";
}
.ion-ios-customer-rank-outline:before {
content: "\e60d";
}
.ion-md-customer-stock:before {
content: "\e610";
}
.ion-ios-customer-stock:before {
content: "\e612";
}
.ion-ios-customer-stock-outline:before {
content: "\e610";
}
$tabs-ios-tab-text-color-active:#f6670B; //設置點擊後的顏色
$tabs-ios-tab-icon-color-active:#f6670B;
$tabs-md-tab-text-color-active:#f6670B;
$tabs-md-tab-icon-color-active:#f6670B;複製代碼
而後在須要的地方,例如在tabs.html
中:chrome
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="{{ 'TABS.TAB1_TITLE' | translate }}" tabIcon="customer-home"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="{{ 'TABS.TAB2_TITLE' | translate }}" tabIcon="customer-rank"></ion-tab>
</ion-tabs>複製代碼
最後,在app.scss中添加如下代碼,防止圖標偏上:npm
.tabs-ios .tab-button-icon::before {
vertical-align: middle;
}複製代碼
使用<ion-content></ion-content>
包裹內容api
使用官方推薦的ngx-translate,而不是ng2-translate。地址是:ionicframework.com/docs/develo… ionic V3是基於Angular2的,因此國際化也是沿用其方法,地址爲:github.com/ngx-transla…
檢測到Token過時,應該跳轉到登陸頁,從新登陸,具體方法是:在須要跳轉的地方,執行如下代碼
this.navCtrl.setRoot(LoginComponent);複製代碼
此時可能會出現底下的Tab顯示的問題,隱藏它:
ngOnInit() {
let elements = document.querySelectorAll(".tabbar");
if (elements != null) {
Object.keys(elements).map((key) => {
elements[key].style.display = 'none';
});
}
}複製代碼
在二級界面中加入以下代碼:
//進入隱藏Tab
ngOnInit() {
let elements = document.querySelectorAll(".tabbar");
if (elements != null) {
Object.keys(elements).map((key) => {
elements[key].style.display = 'none';
});
}
}
//返回至主界面顯示Tab
ngOnDestroy() {
let elements = document.querySelectorAll(".tabbar");
if (elements != null) {
Object.keys(elements).map((key) => {
elements[key].style.display = 'flex';
});
}
}複製代碼
cd /項目的根目錄下
npm install echarts --save複製代碼
而後在使用的.ts文件中導入:
import echarts from 'echarts';複製代碼
ionic V3.X 自己提供了發佈-訂閱風格的應用級別的事件系統Events ,使用起來簡單方便,具體用法見:ionicframework.com/docs/api/ut…