Skip to content

Commit d401dcc

Browse files
committed
加入分包的配置
1 parent 2576e7d commit d401dcc

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

uniapp_uview/common/http.interceptor.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ const install = (Vue, vm) => {
2020

2121
// 请求拦截部分,如配置,每次请求前都会执行
2222
Vue.prototype.$u.http.interceptor.request = (config) => {
23-
console.log('config', config)
23+
console.log('config-http', config)
2424
// 引用token
2525
// 方式一,存放在vuex的token,假设使用了uView封装的vuex方式
2626
// 见:https://uviewui.com/components/globalVariable.html
27-
// config.header.token = vm.token;
27+
config.header.token = vm.vuex_token;
2828

2929
// 方式二,如果没有使用uView封装的vuex方法,那么需要使用$store.state获取
3030
// config.header.token = vm.$store.state.token;
@@ -36,10 +36,9 @@ const install = (Vue, vm) => {
3636
// 所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
3737
// const token = uni.getStorageSync('token');
3838
// config.header.token = token;
39-
config.header.Token = 'xxxxxx';
4039

4140
// 可以对某个url进行特别处理,此url参数为this.$u.get(url)中的url值
42-
if (config.url == '/user/login') config.header.noToken = true;
41+
if (config.url == '/test/jam') config.header.noToken = true;
4342
// 最后需要将config进行return
4443
return config;
4544
// 如果return一个false值,则会取消本次请求
@@ -48,18 +47,19 @@ const install = (Vue, vm) => {
4847

4948
// 响应拦截,如配置,每次请求结束都会执行本方法
5049
Vue.prototype.$u.http.interceptor.response = (res) => {
50+
console.log('res-http',res)
5151
if (res.code == 200) {
5252
// res为服务端返回值,可能有code,result等字段
5353
// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
5454
// 如果配置了originalData为true,请留意这里的返回值
5555
return res.result;
5656
} else if (res.code == 201) {
5757
// 假设201为token失效,这里跳转登录
58-
vm.$u.toast('验证失败,请重新登录');
59-
setTimeout(() => {
60-
// 此为uView的方法,详见路由相关文档
61-
vm.$u.route('/pages/user/login')
62-
}, 1500)
58+
// vm.$u.toast('验证失败,请重新登录');
59+
// setTimeout(() => {
60+
// // 此为uView的方法,详见路由相关文档
61+
// vm.$u.route('/pages/user/login')
62+
// }, 1500)
6363
return false;
6464
} else {
6565
// 如果返回false,则会调用Promise的reject回调,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<view class="content">
3+
分包的页面
4+
</view>
5+
</template>
6+
7+
<script>
8+
export default {
9+
data() {
10+
return {
11+
12+
}
13+
},
14+
onLoad() {
15+
16+
},
17+
methods: {
18+
19+
}
20+
}
21+
</script>
22+
23+
<style lang="scss">
24+
25+
</style>
3.93 KB
Loading

uniapp_uview/pages.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@
22
"easycom": {
33
"^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue"
44
},
5-
"pages": [
6-
//pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
5+
"pages": [
76
{
87
"path": "pages/index/index",
98
"style": {
109
"navigationBarTitleText": "uni-app"
1110
}
1211
}
1312
],
13+
"subPackages": [{
14+
"root": "package_sub",
15+
"pages": [{
16+
"path": "pages/index/index",
17+
"style": {
18+
"navigationBarTitleText": "分包页面sub_index"
19+
}
20+
}]
21+
}],
22+
"preloadRule": {
23+
"package_sub/pages/index/index": {
24+
"network": "all",
25+
"packages": ["__APP__"]
26+
}
27+
},
1428
"globalStyle": {
1529
"navigationBarTextStyle": "black",
1630
"navigationBarTitleText": "uni-app",

uniapp_uview/pages/index/index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<view class="content">
33
<u-icon name="level" color="#2979ff" size="28"></u-icon>
4-
<u-button>默认按钮</u-button>
4+
<u-button @click="onToPage">跳转分包页面</u-button>
55
<u-button type="primary">主要按钮</u-button>
66
<u-button type="success">成功按钮</u-button>
77
<u-button type="info">信息按钮</u-button>
@@ -26,6 +26,11 @@
2626
this.getInfo()
2727
},
2828
methods: {
29+
onToPage(){
30+
uni.navigateTo({
31+
url: '/package_sub/pages/index/index'
32+
});
33+
},
2934
async getSearch(){
3035
let params = {
3136
id:111

0 commit comments

Comments
 (0)