Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
web-framework-temp
/
vue-cli3-vt-template-master
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
64abdf01
authored
2022-03-08 11:46:01 +0800
by
simon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
挂载全局app 让api与小程序一致
1 parent
45cb2495
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
30 deletions
src/api/api.js
src/main.js
src/pages/demo/demo.js
src/pages/index/index.js
src/pages/lottery/lottery.js
src/router.js
src/api/api.js
View file @
64abdf0
module
.
exports
=
{
testListGet
:
'/xxx/xxx/list'
testListGet
:
'/xxx/xxx/list'
,
areaQuery
:
'https://api.k.wxpai.cn/bizproxy/kdapi/area'
,
// post 区域查询
}
\ No newline at end of file
...
...
src/main.js
View file @
64abdf0
import
Vue
from
'vue'
import
App
from
'./App.vue'
import
Vue
App
from
'./App.vue'
import
router
from
'./router'
import
store
from
'./store'
import
api
from
'@/api/api'
import
{
httpGet
,
httpPost
}
from
'@/api/fetch-api.js'
// import Mock from './mock'
// Mock.bootstrap();
...
...
@@ -44,11 +50,21 @@ Vue.use(Swipe).use(SwipeItem)
.
use
(
Button
)
.
use
(
Toast
);
new
Vue
({
let
app
=
new
Vue
({
router
,
store
,
data
:
{
isInit
:
false
,
},
render
:
h
=>
h
(
App
)
render
:
h
=>
h
(
Vue
App
)
}).
$mount
(
'#app'
)
// 挂载全局app
app
.
api
=
api
;
app
.
get
=
httpGet
;
app
.
post
=
httpPost
;
app
.
router
=
router
;
window
.
app
=
app
;
// 原app节点请通过 document.getElementById('app') 获取
// routes里的component组件需要以import方式引入,否则页面创建的时候,app还没挂载。
\ No newline at end of file
...
...
src/pages/demo/demo.js
View file @
64abdf0
import
api
from
'../../api/api'
import
{
httpGet
,
httpPost
}
from
'../../api/fetch-api.js'
export
default
{
data
()
{
return
{
...
...
src/pages/index/index.js
View file @
64abdf0
import
api
from
'../../api/api'
import
{
httpGet
,
httpPost
}
from
'../../api/fetch-api.js'
export
default
{
data
()
{
return
{
...
...
@@ -12,12 +6,12 @@ export default {
},
components
:
{},
methods
:
{
initData
()
{},
toLottery
()
{
this
.
$router
.
push
({
path
:
"/lottery"
})
}
app
.
router
.
push
({
name
:
"lottery"
});
},
initData
()
{},
},
mounted
()
{},
created
()
{
...
...
src/pages/lottery/lottery.js
View file @
64abdf0
import
api
from
'../../api/api'
import
{
httpGet
,
httpPost
}
from
'../../api/fetch-api.js'
export
default
{
data
()
{
return
{
...
...
@@ -18,7 +12,18 @@ export default {
path
:
"/"
})
},
async
queryArea
()
{
let
res
=
await
app
.
post
({
url
:
app
.
api
.
areaQuery
,
data
:
{},
sid
:
false
,
mode
:
"custom"
});
console
.
log
(
"地区查询:"
,
res
);
}
},
mounted
()
{
this
.
queryArea
();
},
mounted
()
{},
created
()
{}
}
\ No newline at end of file
...
...
src/router.js
View file @
64abdf0
import
Vue
from
'vue'
import
Router
from
'vue-router'
import
Index
from
'./pages/index/index.vue'
Vue
.
use
(
Router
)
const
routes
=
[{
path
:
'/'
,
name
:
'index'
,
component
:
Index
,
component
:
()
=>
import
(
'./pages/index/index.vue'
)
,
meta
:
{
title
:
''
}
...
...
Please
register
or
sign in
to post a comment