uniapp的條件編譯


前言:

  uniapp支持多平台,但遇到平台差異的時候怎么辦?這就需要條件編譯

正文:

  1.組件(view類)的條件編譯 

    <!--  #ifdef  MP-WEIXIN -->
      <button>此代碼僅在微信小程序平台出現</button>
    <!--  #endif -->
    <!--  #ifndef H5 -->
        <button>此代碼不會在H5平台出現</button>
    <!--  #endif -->
    <!--  #ifdef APP-PLUS || H5 -->
        <button>此代碼會在App和H5平台出現</button>
    <!--  #endif -->

  2.樣式(css類)的條件編譯

/*  #ifdef  APP-PLUS  */
    /* 僅在app平台顯示 */
    .abc{
        color:#fff;
    }
/*  #endif  */

  3.api(js類)的條件編譯

        //  #ifdef  APP-PLUS
            console.log('此代碼僅在App平台顯示');
        //  #endif
        //  #ifndef H5
            console.log("此代碼不會在H5平台顯示");
        //  #endif
        //  #ifdef APP-PLUS || H5
            console.log("此代碼會在App平台和H5平台顯示");
        //  #endif

  4.pages.json 的條件編譯

//  #ifdef  APP-PLUS
    {
        "path":"pages/index/index"
    }
//  #endif

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM