File tree Expand file tree Collapse file tree 9 files changed +101
-63
lines changed Expand file tree Collapse file tree 9 files changed +101
-63
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " vue-cli-electron-template" ,
3- "version" : " 0.2.1 " ,
3+ "version" : " 0.3.0 " ,
44 "private" : true ,
55 "scripts" : {
66 "serve" : " vue-cli-service serve" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import resources from './resources'
2+
3+ export default resources
Original file line number Diff line number Diff line change 1+ import axios from 'axios'
2+
3+ // Full config: https://github.com/axios/axios#request-config
4+ /* axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
5+ axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
6+ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; */
7+
8+ const config = {
9+ /* baseURL: process.env.baseURL || process.env.apiUrl || ""
10+ timeout: 60 * 1000, // Timeout
11+ withCredentials: true, // Check cross-site Access-Control
12+ headers: { 'Content-Type': 'application/json' } */
13+ }
14+
15+ const $axios = axios . create ( config )
16+
17+ $axios . interceptors . request . use (
18+ function ( config ) {
19+ // Do something before request is sent
20+ return config
21+ } ,
22+ function ( error ) {
23+ // Do something with request error
24+ return Promise . reject ( error )
25+ }
26+ )
27+
28+ // Add a response interceptor
29+ $axios . interceptors . response . use (
30+ function ( response ) {
31+ // Do something with response data
32+ return response
33+ } ,
34+ function ( error ) {
35+ // Do something with response error
36+ return Promise . reject ( error )
37+ }
38+ )
39+
40+ export default $axios
Original file line number Diff line number Diff line change 1+ import axios from '../requester'
2+
3+ // Api resources here
4+ export default {
5+ // Async await
6+ async demoGetV1 ( ) {
7+ return ( await axios . get ( 'http://example.com/' ) ) . data
8+ } ,
9+ demoPostV1 ( ) {
10+ return axios . post ( 'http://example.com/' ) . then ( response => response . data )
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ import axios from '../requester'
2+
3+ // Api resources here
4+ export default {
5+ // Async await
6+ async demoGetV2 ( ) {
7+ return ( await axios . get ( 'http://example.com/' ) ) . data
8+ } ,
9+ demoPostV2 ( ) {
10+ return axios . post ( 'http://example.com/' ) . then ( response => response . data )
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ import axios from '../requester'
2+
3+ // Api resources here
4+ export default {
5+ // Async await
6+ async publicGet ( ) {
7+ return ( await axios . get ( 'http://example.com/' ) ) . data
8+ } ,
9+ publicPost ( ) {
10+ return axios . post ( 'http://example.com/' ) . then ( response => response . data )
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ import apiV1 from './api_v1'
2+ import apiV2 from './api_v2'
3+ import common from './common'
4+
5+ export default {
6+ apiV1,
7+ apiV2,
8+ ...common // Deconstruction
9+ }
Original file line number Diff line number Diff line change 1515 <h2 >Author: PurePeace</h2 >
1616 <h2
1717 style =" cursor : pointer ; color : #FFF ;"
18- @click =" ()=>{const {shell} = require('electron'); shell.openExternal(link)}"
18+ @click ="
19+ () => {
20+ const { shell } = require('electron')
21+ shell.openExternal(link)
22+ }
23+ "
1924 >
2025 Github: <span style =" user-select : text ;" >{{ link }}</span >
2126 </h2 >
2227 </div >
2328</template >
2429
2530<script >
26-
2731export default {
2832 data () {
2933 return {
@@ -32,17 +36,13 @@ export default {
3236 }
3337 },
3438 methods: {
35- sendRequest () {
39+ // Async request
40+ async sendRequest () {
41+ console .log (this .$backend )
3642 this .buttonText = ' requestDemo.requesting'
37- this .$backend .demoGet (
38- // 参数 / parameter
39- ).then (res => {
40- console .log (res)
41- this .buttonText = ' requestDemo.requestSuccess'
42- }).catch (error => {
43- console .log (error)
44- this .buttonText = ' requestDemo.requestFail'
45- })
43+ const res = await this .$backend .apiV2 .demoGetV2 ()
44+ this .buttonText = ' requestDemo.requestSuccess'
45+ console .log (res)
4646 }
4747 }
4848}
You can’t perform that action at this time.
0 commit comments