Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template lang="pug">
- .container
- h1 {{msg}}
- pre {{token}}
- pre {{user}}
- .row
- .col-sm-6
- .form
- .form-group
- input.form-control(v-model="user.username")
- .form-group
- input.form-control(type="password" v-model="user.password")
- .form-group
- .btn.btn-success(@click="login") Click
- .form-group
- .btn.btn-primary(@click="check") Check
- .col-sm-6
- form(methods="POST" action="/login")
- .form-group
- input.form-control(v-model="user.username" name="username")
- .form-group
- input.form-control(type="password" v-model="user.password" name="password")
- .form-group
- input(type="submit")
- </template>
- <script>
- import axios from 'axios'
- export default {
- name: 'app',
- data () {
- return {
- msg: 'Welcome to Your Vue.js App',
- user: {
- username: '',
- password: ''
- },
- currentUser: {},
- token: ''
- }
- },
- methods: {
- login () {
- console.log('loging....')
- console.log(this.user.username, this.user.password)
- axios.post('/login', {
- username: this.user.username,
- password: this.user.password,
- }).then(res => {
- this.token = res.data.token,
- this.currentUser = res.data.user
- console.log(res.data)
- }, err => {
- console.err(err)
- })
- },
- check () {
- let getCookie = (name) => {
- var matches = document.cookie.match(new RegExp(
- "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
- ));
- return matches ? decodeURIComponent(matches[1]) : undefined;
- }
- let token = getCookie('token')
- if (token) {
- axios.get('/dashboard', {
- headers: {
- id: token
- }
- }).then(res => {
- console.log('eeeeeeeeeeeee', true)
- console.log(res.headers)
- return true
- }, err => {
- return false
- console.err(err)
- })
- } else {
- console.log(false)
- }
- }
- }
- }
- </script>
Add Comment
Please, Sign In to add comment