Install the NPM dependency
npm install uview-ui 
For the development environment, please add the following conditional compilation to the baseURL: appconfig. ServerURL in the http.interceptor.js file
// #ifndef H5
    baseUrl: appconfig.serverUrl,
// #endif

The development environment configures vue.config.js across domains

Formalized environments can remove the baseURL: AppConfig. ServerURL conditional compilation from the http.interceptor.js file into the following form
baseUrl: appconfig.serverUrl,
The domain names in vue.config.js and config.js will be changed as well

  • main.js

import Vue from 'vue' import App from './App' import store from './store' import * as utils from '@/common/utils.js' import uView from "uview-ui"; Vue.use(uView); import cuCustom from 'colorui/components/cu-custom.vue' Vue.component('cu-custom',cuCustom) Vue.config.productionTip = false Vue.prototype.$store = store Vue.prototype.$utils = utils App.mpType = 'app' const app = new Vue({ ... App}) // HTTP interceptor, which is what needs to be added, if not written in the common directory, Please make your own modifications introduced path import httpInterceptor from '@ / common/HTTP. Interceptor. Js' / / there needs to be written in the end, is for the sake of Vue such as object creation is complete, Introduce the "app" object (i.e., the "this" instance of the page) vue.use (HttpInterceptor, $mount() from '@/common/http.api.js' vue.use (httpApi, app) app.$mount()
  • config.js

Export default {apiurl: ", ServerUrl :"",// server interface API address, local cross-domain configuration temporarily empty imageUrl:"",// service image loading address imgupload:"",// image uploading address appid:""// public account appid}
  • http.api.js

Import AppConfig from './config.js' // If the domain name is not configured via the interceptor, you can write the full URL here (plus the domain name part) let loginURL ="" This is what we use on the page. You can get actions like vuex through the VM. For more information, see the UView section on interceptors:  // https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F const install = (Vue, vm) = > {/ / use the incoming params parameters let login = (params = {}) = > vm. $u.p ost (loginUrl, {username: params. Username, password:params.password }); $u.api = {login}; $u.api = {login}; $u.api = {login}; } export default { install }
  • http.interceptor.js

// import AppConfig from './config.js'; // import this from './config.js'; Vue.prototype.$u.http.setConfig({baseURL: // In this time, if the request is not returned, the animation will be displayed in ms originalData: If the server status code is not 200 when the original data of the server is false in the interceptor, the modal shell will prompt loadingMask: True, // ShowLoading should be displayed with a transparent mask to prevent touching from penetrating: Parse () dataType: 'json', parse() dataType: 'json', request header: {'content-type': 'application/json', } }); / / request intercept, configuration Token Vue. The parameters such as the prototype. $u.h TTP. The interceptor. Request = (config) = > {/ reference/Token console. The log (" intercept request: "config); // The Vuex token is stored in the Vuex token, and the Vuex token is encapsulated in a UView. https://uviewui.com/components/globalVariable.html // config.header.token = vm.token; $store.state = vm.$store.state = vm.$store. // Config. Header. token = getApp().globalData.Username; // Config. // If the token is stored in the Storage local Storage, interception is performed on every request // So even if you log in again and modify the Storage, The next request will be the latest value const token = uni.getStorageSync('token'); config.header.token = token; // if(config.url == '/user/login') config.header.noToken = true; // if(config.url == '/user/login') config.header.noToken = true; Return config; return config; return config; If (config.url == '/user/rest') return false; if(config.url == '/user/rest') return false; /} / cancel a request/response to intercept, judge whether a status code through the Vue. Prototype. $u.h TTP. The interceptor. The response = (res) = > {/ / console log (", "response to intercept, res); Return res; // return res; // if(res.code == 200) {// // res.code == 200; If (res => {}) then(res => {}); if (res => {}) then(res => {}); if (res => {}); //} else if(res.code == 201) {// // if 201 is the token invalid. log in // vm.$u.toast(' Verify failed, please login again '); $vm.$u.Route ('/pages/user/login') //}, 1500) // return false; //} else {// // If false is returned, the reject callback of Promise is called, and this.$u.ost (url).then().catch(res=>{}) is called. Res is the server return value // return false; // } } } export default { install }