mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
b11e9c0e51
- [ ] babel-eslint https://github.com/babel/babel-eslint/issues/664 - [x] eslint-config-standard-jsx https://github.com/standard/eslint-config-standard-jsx/issues/32 - [x] eslint-config-standard to be stable release https://github.com/standard/eslint-config-standard/issues/123 - [x] eslint-plugin-html - [x] eslint-plugin-import - [x] eslint-plugin-jest - [x] eslint-plugin-node - [x] eslint-plugin-promise - [x] eslint-plugin-standard https://github.com/standard/eslint-plugin-standard/issues/29 - [x] eslint-plugin-vue https://github.com/vuejs/eslint-plugin-vue/pull/504 - [x] eslint-plugin-react https://github.com/yannickcr/eslint-plugin-react/releases/tag/v7.10.0
63 lines
1.6 KiB
Vue
63 lines
1.6 KiB
Vue
<template>
|
|
<div class="container">
|
|
<h1>Please login to see the secret content</h1>
|
|
<form v-if="!$store.state.authUser" @submit.prevent="login">
|
|
<p v-if="formError" class="error">{{ formError }}</p>
|
|
<p><i>To login, use <b>demo</b> as username and <b>demo</b> as password.</i></p>
|
|
<p>Username: <input v-model="formUsername" type="text" name="username"></p>
|
|
<p>Password: <input v-model="formPassword" type="password" name="password"></p>
|
|
<button type="submit">Login</button>
|
|
</form>
|
|
<div v-else>
|
|
Hello {{ $store.state.authUser.username }}!
|
|
<pre>I am the secret content, I am shown only when the use is connected.</pre>
|
|
<p><i>You can also refresh this page, you'll still be connected!</i></p>
|
|
<button @click="logout">Logout</button>
|
|
</div>
|
|
<p><nuxt-link to="/secret">Super secret page</nuxt-link></p>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
formError: null,
|
|
formUsername: '',
|
|
formPassword: ''
|
|
}
|
|
},
|
|
methods: {
|
|
async login() {
|
|
try {
|
|
await this.$store.dispatch('login', {
|
|
username: this.formUsername,
|
|
password: this.formPassword
|
|
})
|
|
this.formUsername = ''
|
|
this.formPassword = ''
|
|
this.formError = null
|
|
} catch (e) {
|
|
this.formError = e.message
|
|
}
|
|
},
|
|
async logout() {
|
|
try {
|
|
await this.$store.dispatch('logout')
|
|
} catch (e) {
|
|
this.formError = e.message
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.container {
|
|
padding: 100px;
|
|
}
|
|
.error {
|
|
color: red;
|
|
}
|
|
</style>
|