代码拉取完成,页面将自动刷新
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。