main.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // #ifndef VUE3
  2. import Vue from 'vue'
  3. import App from './App'
  4. //导入网络请求包
  5. import {$http} from '@escook/request-miniprogram'
  6. //5.导入store的自定义模块
  7. import store from '@/information/store.js'
  8. //导入uView组件库
  9. import uView from '@/uni_modules/uview-ui'
  10. Vue.use(uView)
  11. //挂载到uni.$http上方便调用
  12. uni.$http = $http
  13. //请求根路径
  14. // $http.baseUrl = 'https://www.uinav.com'
  15. //挂载请求拦截器
  16. $http.beforeRequest = function(options) {
  17. uni.showLoading({
  18. title: '数据加载中...'
  19. })
  20. //挂载请求头
  21. //判断当前请求的是否为有权限的接口
  22. // if(options.url.indexOf('/pages/login/login') !== -1){
  23. //为header中添加必要信息(权限字段)
  24. // options.header = {
  25. // }
  26. //}
  27. }
  28. //挂载响应拦截器
  29. $http.afterRequest = function() {
  30. uni.hideLoading()
  31. }
  32. //封装的展示消息提示方法
  33. uni.$showMsg = function(title = '请求失败', duration = 1500){
  34. uni.showToast({
  35. title,
  36. duration,
  37. icon: 'none'
  38. })
  39. }
  40. Vue.config.productionTip = false
  41. App.mpType = 'app'
  42. //app实例对象
  43. const app = new Vue({
  44. ...App,
  45. //6.挂载到app实例对象里
  46. store
  47. })
  48. app.$mount()
  49. // #endif
  50. // #ifdef VUE3
  51. import { createSSRApp } from 'vue'
  52. import App from './App.vue'
  53. export function createApp() {
  54. const app = createSSRApp(App)
  55. return {
  56. app
  57. }
  58. }
  59. // #endif