在根目录创建common文件夹,再创建公共的js文件
util.js
import Vue from 'vue'
# 如果需要访问this,需要引入Vue实例,如果需要路由则需要引入路由,(需要使用到什么就引入什么)
function showLoading(message){
if (message){
message = '加载中';
}
uni.showLoading({
title: message
});
setTimeout(function () {
uni.hideLoading();
}, 2000);
}
function hideLoading(){
uni.hideLoading();
}
function showCommontModal(message){
if (message){
message = "参数错误!!!";
}
uni.showModal({
title: '温馨提示',
content: message,
showCancel:false,
success: function (res) {
console.log('用户点击确定');
}
});
}
module.exports = {
showLoading: showLoading,
hideLoading:hideLoading,
showCommontModal:showCommontModal,
}
在main.js文件中引入js文件
在vue页面中直接使用