Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
swx_weapp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2022-10-10 11:07:26 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b11ea90560e5a574f10a3a14644aea25354cfa57
b11ea905
1 parent
dde019fb
✨ feat: 配置API接口请求,处理cookie参数问题
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
8 deletions
src/app.js
src/utils/config.js
src/utils/request.js
src/app.js
View file @
b11ea90
/*
* @Date: 2022-09-19 14:11:05
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-
09-28 14:18:13
* @LastEditTime: 2022-
10-09 18:09:06
* @FilePath: /swx/src/app.js
* @Description: 文件描述
*/
...
...
@@ -10,10 +10,31 @@ import { createPinia } from 'pinia'
import
'./app.less'
import
'@/components/vant-weapp/common/index.wxss'
import
request
from
'./utils/request'
;
const
App
=
createApp
({
// 可以使用所有的 Vue 生命周期方法
mounted
()
{
},
mounted
()
{
// TODO: 现在先传openid,小程序的密钥还有搞到
// 保存主办方信息
request
.
post
(
'/srv/?a=openid'
,
{
openid
:
'wxa2e50e76487d1d7b'
})
.
then
(
res
=>
{
if
(
res
.
data
.
code
)
{
// console.warn(res.data.data);
var
cookie
=
res
.
cookies
[
0
];
if
(
cookie
!=
null
)
{
wx
.
setStorageSync
(
"sessionid"
,
res
.
cookies
[
0
]);
//服务器返回的 Set-Cookie,保存到本地
}
}
else
{
console
.
warn
(
res
.
data
.
msg
);
}
})
.
catch
(
err
=>
{
console
.
error
(
err
);
});
},
// 对应 onLaunch
onLaunch
()
{
},
...
...
src/utils/config.js
View file @
b11ea90
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-
09-19 14:19:05
* @LastEditTime: 2022-
10-09 15:41:43
* @FilePath: /swx/src/utils/config.js
* @Description: 文件描述
*/
const
BASE_URL
=
"http://
voice
.onwall.cn"
;
const
BASE_URL
=
"http://
wenxuan
.onwall.cn"
;
export
default
BASE_URL
...
...
src/utils/request.js
View file @
b11ea90
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-
09-19 14:19:18
* @LastEditTime: 2022-
10-09 18:21:32
* @FilePath: /swx/src/utils/request.js
* @Description: 简单axios封装,后续按实际处理
*/
...
...
@@ -16,17 +16,21 @@ import BASE_URL from './config';
const
service
=
axios
.
create
({
baseURL
:
BASE_URL
,
// url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout
:
5000
// request timeout
timeout
:
5000
,
// request timeout
headers
:
{
//TAG 小程序绑定cookie
'cookie'
:
wx
.
getStorageSync
(
"sessionid"
)
//读取本地保存好的上⼀次cookie
}
})
service
.
defaults
.
params
=
{
f
:
'
voice
'
,
f
:
'
swx
'
,
};
// request interceptor
service
.
interceptors
.
request
.
use
(
config
=>
{
console
.
warn
(
config
)
//
console.warn(config)
// console.warn(store)
return
config
...
...
Please
register
or
login
to post a comment