赞
踩
<template> <div class="m-content"> <h3>欢迎来到172055110吕泽江的博客</h3> <div class="block"> <el-avatar :size="50" :src="user.avatar"></el-avatar> <div>{ { user.username }}</div> </div> <div class="maction"> <span><el-link href="/blogs">主页</el-link></span> <el-divider direction="vertical"></el-divider> <span><el-link type="success" href="/blog/add">发表博客</el-link></span> <el-divider direction="vertical"></el-divider> <span v-show="!hasLogin"><el-link type="primary" href="/login">登录</el-link></span> <span v-show="hasLogin"><el-link type="danger" @click="logout">退出</el-link></span> </div> </div> </template> <script> export default { name: "Header", data() { return { user: { username: '请先登录', avatar: 'https://profile.csdnimg.cn/E/6/0/2_lvjzzz\n' }, //默认未登录 hasLogin: false } }, methods: { //退出方法 logout() { const _this = this //发起请求 _this.$axios.get("/logout", { headers: { "Authorization": localStorage.getItem("token") } }).then(res => { //移除信息 _this.$store.commit("REMOVE_INFO") //跳转至登录页面 _this.$router.push("/login") }) } }, //回写,获取store信息 created() { if(this.$store.getters.getUser.username) { //用户信息不为空则回写内容 this.user.username = this.$store.getters.getUser.username this.user.avatar = this.$store.getters.getUser.avatar this.hasLogin = true } } } </script> <style scoped> .m-content { max-width: 960px; margin: 0 auto; text-align: center; } .maction { margin: 10px 0; } </style>
<template>
<div class="mcontaner">
<Header></Header>
<div class="block">
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。