uni app中建立公共方法utils

uni app中建立公共方法utils
有一些公 用的方法可以抽出来的,像日期格式化之类的
步骤:
1. 建立文件 common/utils.js 文件


/**
 * 返回欢迎文本
 * @param string name 姓名
 */
export const testFun = function(name){
    return "hello: "+name;
}




2. App.vue 中加入以下语句,放在vue import后面



import * as utils from './common/utils.js' 
Vue.prototype.$utils = utils;



3. 然后在每个页面里就可以直接使用了


methods: {
    //测试方法
    aaa(){
        alert(this.$utils.testFun('牛腩')); 
    }, 
 }