add actions, mutations

This commit is contained in:
Jay
2018-08-17 23:59:03 +08:00
parent 06e2bfded6
commit 218721bc15
5 changed files with 32 additions and 20 deletions
+18 -6
View File
@@ -11,13 +11,9 @@
<input placeholder="Password" v-model="password">
</sui-form-field>
<sui-button type="submit" fluid color='teal'>Login</sui-button>
<sui-button type="button" @click="go_oauth" class="twitch-button" fluid color='violet'>Login with Twitch</sui-button>
</sui-form>
</sui-segment>
<sui-message>
<div class="oauth">
or login with <a href="#">twitch</a> ?
</div>
</sui-message>
</div>
</sui-container>
</template>
@@ -31,11 +27,16 @@
.oauth {
text-align: center;
}
.twitch-button {
margin-top: 10px;
}
}
</style>
<script>
import {mapMutations} from 'vuex'
import {mapMutations, mapActions} from 'vuex'
import {apiUrl} from '@/tools'
export default {
name: 'LoginForm',
data () {
@@ -44,14 +45,25 @@ export default {
password: ''
}
},
created () {
this.checkSession((flag) => {
// check login session
// true === isLogin
console.log(flag)
})
},
methods: {
...mapMutations(['toggleLoading']),
...mapActions(['checkSession']),
login: function () {
console.log('login submit')
this.toggleLoading(1)
setTimeout(() => {
this.toggleLoading(0)
}, 1000)
},
go_oauth: function () {
window.location.href = apiUrl.replace(/\/$/, '') + '/twitch/login?tourl=' + encodeURIComponent(window.location.href)
}
},
mounted: function () {
+2 -3
View File
@@ -1,6 +1,7 @@
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './actions'
import * as getters from './getters'
Vue.use(Vuex)
@@ -11,7 +12,5 @@ export default new Vuex.Store({
},
mutations,
getters,
actions: {
}
actions
})
-5
View File
@@ -1,5 +0,0 @@
export default {
toggleLoading (state, loading = null) {
state.loading = !!loading
}
}