zoukankan      html  css  js  c++  java
  • Vue Abp vNext获取当前登录用户

    系统默认提供了获取当前用户的api方法

    https://localhost:44364/api/identity/my-profile

     手工实现方法:abp后台获取当前用户需要在AppService应用层注入CurrentUser currentUser,如本例

    using System;
    using Volo.Abp.Application.Dtos;
    using Volo.Abp.Application.Services;
    using Volo.Abp.Domain.Repositories;
    using Volo.Abp.Users;
    
    namespace Shop
    {
        public class BookAppService :
            CrudAppService<Book, BookDto, Guid, PagedAndSortedResultRequestDto,
                CreateUpdateBookDto, CreateUpdateBookDto>,
            IBookAppService
        {
            private readonly CurrentUser _currentUser;
    
            public BookAppService(IRepository<Book, Guid> repository, CurrentUser currentUser) : base(repository)
            {
                _currentUser = currentUser;
            }
    
            public CurrentUser GetUser()
            {
                var currentUser = _currentUser;
                return currentUser;
            }
        }
    }

    Vue前台获取方式,创建user.vue

    <template>
        <div>
            <el-button @click="btnCurrentUser">当前登录用户</el-button>
            <hr/>
            {{CurrentUser}}
        </div>
    </template>
    <script>
        export default {
            data(){
                return{
                    CurrentUser:''
                }
            },
            methods: {
                btnCurrentUser: function () {
                    this.$axios.get('https://localhost:44327/api/app/book/user')
                        .then(res => {
                            this.CurrentUser = res.data
                        })
                }
            }
        }
    </script>

    router目录index.js中增加路由规则

    import Vue from 'vue'
    import VueRouter from 'vue-router'
    import Home from '../views/Login.vue'
    
    Vue.use(VueRouter)
    
      const routes = [
      {
        path: '/',
        name: 'Home',
        component: Home
      },
      {
        path: '/about',
        name: 'About',
        component: () => import('../views/About.vue')
      },
        {
          path: '/user',
          name: 'user',
          component: () => import('../views/user.vue')
        }
    ]
    
    const router = new VueRouter({
      routes
    })
    
    export default router

    前台显示

    后台中也可以根据CurrentUser获取用户id等详情

  • 相关阅读:
    Android 使用WebView显示网页
    Android 使用ProgressBar实现进度条
    Android 使用Spinner实现下拉列表
    Android 使用GridView以表格的形式显示多张图片
    Android 使用DatePicker以及TimePicker显示当前日期和时间
    Android 使用ListView显示信息列表
    IIS配置步骤,绝对有用,百度上的不全面,是百度的补充
    冒烟测试
    广度优先和深度优先
    排序算法二(时间复杂度为O(N*logN))
  • 原文地址:https://www.cnblogs.com/liessay/p/13181584.html
Copyright © 2011-2022 走看看