tangjinzhou пре 6 година
родитељ
комит
bb6746229d
2 измењених фајлова са 29 додато и 0 уклоњено
  1. 16 0
      src/components/Authorized.vue
  2. 13 0
      src/directives/auth.js

+ 16 - 0
src/components/Authorized.vue

@@ -0,0 +1,16 @@
+<script>
+import { check } from "../utils/auth";
+export default {
+  functional: true,
+  props: {
+    authority: {
+      type: Array,
+      required: true
+    }
+  },
+  render(h, context) {
+    const { props, scopedSlots } = context;
+    return check(props.authority) ? scopedSlots.default() : null;
+  }
+};
+</script>

+ 13 - 0
src/directives/auth.js

@@ -0,0 +1,13 @@
+import { check } from "../utils/auth";
+
+function install(Vue, options = {}) {
+  Vue.directive(options.name || "auth", {
+    inserted(el, binding) {
+      if (!check(binding.value)) {
+        el.parentNode && el.parentNode.removeChild(el);
+      }
+    }
+  });
+}
+
+export default { install };