<template>
    <div v-if="show">
        <slot v-if="show"></slot>
    </div>
  </template>
  <script>
  import permissionApi from "@/api/sys/permission";
  import { mapState } from 'vuex';
  
  export default {
      props: ["method","path"],
      data() {
          return {
              show: false
          }
      },
      computed: mapState({
          permissions:state=>state.permission.permissions
      }),
      mounted() {
          //vuex中记录method+path是否能访问
          if(this.permissions[this.method + '_' + this.path]!=null){
              this.show = this.permissions[this.method + '_' + this.path];
          }
          else{
            
              permissionApi.hasPermission(this.method,this.path).then((resp)=>{
                  var jsonData = resp.data;
                  this.show = jsonData.result;
  
                  this.$store.commit('permission/SET_PERMISSION', {
                      method: this.method,
                      path: this.path,
                      result: this.show
                  });
              });
          }
      },
      methods: {
  
      }
  }
  </script>
  <style>
  
  </style>