uniApp开发之公用配置文件common.js

在开发uniApp应用时,我们会用上一些自己的函数库和配置,这时我们就要新建一个公用的common.js引入。

module.exports ={
    apiHost:"https://www.deituicms.com",
    getAuthCode:function(){
    var authcode=uni.getStorageSync("authcode");
    if(!authcode){
        authcode=this.getCookie("authcode");
    }
    return authcode;
    },
    setAuthCode:function($authcode){
    uni.setStorageSync("authcode",$authcode);
    },
    get:function(){
    },
    post:function(){
    }
}

在main.js中引入

import $app from "./common/common.js";
Vue.prototype.app=$app;

在index.vue中使用

export default{
    created:function(){
        this.app.get();
    }
}

原文地址:http://www.deituicms.com/module.php?m=ask&a=show&askid=53

posted @ 2021-05-10 21:47  张志健  阅读(2080)  评论(0编辑  收藏  举报