2 Star 1 Fork 1

hanzhengyu/uni-shop-app

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.js 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
Running-hzy 提交于 2020-07-06 18:51 . 用户信息修改&头像上传
import Vue from 'vue'
import store from './store'
import App from './App'
import Json from './Json' //测试用数据
/**
* 因工具函数属于公司资产, 所以直接在Vue实例挂载几个常用的函数
* 所有测试用数据均存放于根目录json.js
*
* css部分使用了App.vue下的全局样式和iconfont图标,有需要图标库的可以留言。
* 示例使用了uni.scss下的变量, 除变量外已尽量移除特有语法,可直接替换为其他预处理器使用
*/
const msg = (title, duration=1500, mask=false, icon='none')=>{
//统一提示方便全局修改
if(Boolean(title) === false){
return;
}
uni.showToast({
title,
duration,
mask,
icon
});
}
const json = type=>{
//模拟异步请求数据
return new Promise(resolve=>{
setTimeout(()=>{
resolve(Json[type]);
}, 500)
})
}
const prePage = ()=>{
let pages = getCurrentPages();
let prePage = pages[pages.length - 2];
// #ifdef H5
return prePage;
// #endif
return prePage.$vm;
}
Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {msg, json, prePage};
//img接口地址前缀
Vue.prototype.$api_img = 'http://localhost:8001/img';
Vue.prototype.$api_auth = 'http://localhost:9002/auth/consumer';
Vue.prototype.$api_user = 'http://localhost:9002/user/consumer';
Vue.prototype.$api_search = 'http://localhost:9003/search';
/**
* 定义埋点事件 v-log
*/
Vue.directive('log', {
bind( el, binding ){
el.addEventListener('click', ()=>{
console.log("埋点事件")
console.table(binding)
uni.request({ //像后端发送埋点数据
url: 'http://localhost:8001/img/log',
method: 'POST',
data: binding.value
}).then(data => {//data为一个数组,数组第一项为错误信息,第二项为返回数据
var [error, res] = data;
console.log(res.data.data);
})
})
}
});
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML/CSS
1
https://gitee.com/hanzhengyu/uni-shop-app.git
git@gitee.com:hanzhengyu/uni-shop-app.git
hanzhengyu
uni-shop-app
uni-shop-app
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385