Refactor axios & Owner page
This commit is contained in:
@@ -5,6 +5,7 @@ import { app } from './services'
|
||||
import { i18n } from './i18n'
|
||||
import store from './store'
|
||||
import './services/ui'
|
||||
import './services/axios'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
Vue.config.devtools = app.dev
|
||||
|
||||
4
src/services/axios.js
Normal file
4
src/services/axios.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import app from './app'
|
||||
|
||||
axios.defaults.baseURL = app.dev ? 'http://localhost:6842/' : 'http://test-sg.bittic.net:6842/'
|
||||
@@ -1,3 +1,5 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
|
||||
@@ -27,15 +29,30 @@ export default {
|
||||
],
|
||||
fetching: false,
|
||||
filter: '',
|
||||
balance: 0,
|
||||
},
|
||||
|
||||
mutations: {
|
||||
inputFilter(state, filter) {
|
||||
state.filter = filter
|
||||
},
|
||||
|
||||
updateBalance(state, balance) {
|
||||
state.balance = balance
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
async queryAccount({ state, commit }) {
|
||||
let account = sessionStorage.getItem('KEY_ACCOUNT')
|
||||
try {
|
||||
account = JSON.parse(account)
|
||||
const result = await axios.post('api/Account/getBalance', {
|
||||
Account: { address: account.address },
|
||||
})
|
||||
commit('updateBalance', result.data || 0)
|
||||
} catch (e) {}
|
||||
},
|
||||
},
|
||||
|
||||
getters: {},
|
||||
|
||||
@@ -54,19 +54,12 @@
|
||||
import {
|
||||
createNamespacedHelpers,
|
||||
} from 'vuex'
|
||||
import axios from 'axios'
|
||||
|
||||
const { mapState, mapGetters, mapActions, mapMutations } = createNamespacedHelpers('owner')
|
||||
|
||||
export default {
|
||||
name: 'Owner',
|
||||
|
||||
data(){
|
||||
return {
|
||||
balance:0,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState([
|
||||
'headers',
|
||||
@@ -74,27 +67,18 @@ export default {
|
||||
'pageEntity',
|
||||
'fetching',
|
||||
'filter',
|
||||
'balance',
|
||||
]),
|
||||
...mapGetters([]),
|
||||
},
|
||||
created:async function(){
|
||||
|
||||
mounted() {
|
||||
this.queryAccount()
|
||||
},
|
||||
mounted:async function(){
|
||||
let account=sessionStorage.getItem('KEY_ACCOUNT')
|
||||
try{
|
||||
account=JSON.parse(account)
|
||||
let result=await axios({
|
||||
method:'post',
|
||||
url:location.protocol+'//'+location.hostname+':6842/api/Account/getBalance',
|
||||
data: {Account:{address:account.address}}
|
||||
})
|
||||
this.balance=result.data||0
|
||||
} catch(e){}
|
||||
}
|
||||
,
|
||||
|
||||
methods: {
|
||||
...mapActions([
|
||||
'queryAccount',
|
||||
]),
|
||||
...mapMutations([
|
||||
'inputFilter',
|
||||
|
||||
Reference in New Issue
Block a user