Code Monkey home page Code Monkey logo

vue-access-control's Introduction

vue-access-control's People

Contributors

dependabot[bot] avatar tower1229 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-access-control's Issues

分配权限

请教一个问题,那管理员分配权限那部分如何实现

丰富注释

将源码整理一遍,加上详细的注释

在main.js注册has指令,在bind钩子函数里removeChild会报错,找不到父节点

在main.js注册has指令,在bind钩子函数里removeChild会报错,找不到父节点,换成inserted就好了
TypeError: Cannot read property 'removeChild' of null

ps:我没有直接使用你的权限控制,而 只是模仿你的注册自定义指令代码,就遇到了这个问题,不知道有何解?

code:

// main.js
Vue.directive('has', {
  inserted: function (el, binding) {
    if (!Vue.prototype.$_has(binding.value)) {
      el.parentNode.removeChild(el)
    }
  }
})
// Layout.vue(app.vue routerview的节点)
created () {
  this.$store.dispatch('getUserInfo')
}
// store.js 
getUserInfo () {
.....
 service.get('/userinfo').then(user => {
     commit('setUserInfo', user)
     Vue.prototype.$_has = function (rArray) {
        let requiredPermission = []
        let permission = true
        if (Array.isArray(rArray)) {
           rArray.forEach(role => {
               requiredPermission = requiredPermission.concat(role)
           })
        } else {
             requiredPermission.push(rArray)
        }
        if (!requiredPermission.includes(role)) {
           permission = false
        }
          return permission
     }
})
....

}

npm run lint,then show some errors:error: Parsing error: Cannot find module 'babel-eslint' at src\views\common\abstract.vue:

I cloned the repo ,then npm run lint,show many errors:

.......
xxxxxxxxxxxxx
......
error: Parsing error: Cannot find module 'babel-eslint' at src\views\roles.vue:
1 | <style scoped>
2 |
3 | .extendGroup {
4 | float: right;
5 | margin-right: 20px;
6 | opacity: 0;
7 | }
8 |
9 | .el-tree-node__content:hover .extendGroup {
10 | opacity: 1;
11 | }
12 | </style>
13 |
14 |
15 |


16 |
17 |

18 | <el-button size="small" type="primary" v-has="[role.request]" @click="fetchData">查询
19 | 删除
20 | 重置
21 | <el-button size="small" type="info" @click="requestNotAllowed">尝试发起越权请求
22 |

23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | 编辑
34 | 删除
35 |
36 |
37 |
38 |
39 |

40 |
41 |
42 | <script>
43 | import * as role from '../api/role';
44 |
45 | let myMixin = {
46 | data: function() {
47 | return { role }
48 | }
49 | }
50 |
51 | export default {
52 | mixins: [myMixin],
53 | data() {
54 | return {
55 | list: [],
56 | canReset: true,
57 | loading: false
58 | }
59 | },
60 | methods: {
61 | fetchData() {
62 | this.loading = true;
63 | role.request.r().then((res) => {
64 | this.list = res.data.content;
65 | this.loading = false;
66 | });
67 | },
68 | requestNotAllowed: function(){
69 | role.notAllowed.r();
70 | }
71 | },
72 | created() {
73 | this.fetchData()
74 | }
75 | }
76 | </script>

error: Parsing error: Cannot find module 'babel-eslint' at babel.config.js:
1 | module.exports = {
2 | presets: [
3 | '@vue/app'
4 | ]
5 | }
6 |

error: Parsing error: Cannot find module 'babel-eslint' at vue.config.js:
1 | module.exports = {
2 | outputDir: 'docs',
3 | baseUrl: process.env.NODE_ENV === 'production'
4 | ? '/Vue-Access-Control/'
5 | : '/'
6 | }

22 errors found.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] lint: vue-cli-service lint
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\changhong\AppData\Roaming\npm-cache_logs\2018-12-04T07_54_27_514Z-debug.log

how to fix it?

指令v-has只能在自定义组件中使用,而无法在原生HTML标签中使用

你好。
v-has在原生HTML标签中使用时,如果判断条件满足,会因为el查找不到父节点而报错。不知是否设计如此,只允许在自定义组件中使用。

<!--报错代码-->
<div class="operation" v-has="[goods.remove]"></div> 
[Vue warn]: Error in directive has bind hook: "TypeError: Cannot read property 'removeChild' of null"

TypeError: Cannot read property 'removeChild' of null

是否可以通过在bind方法中设置元素隐藏,然后在inserted方法中移除元素的方式实现。

Hi i have issue. npm run dev after printing this log

WAIT Compiling... 11:04:23 AM
94% asset optimization

ERROR Failed to compile with 4 errors 11:04:25 AM
error in ./src/App.vue

Syntax Error: Unexpected token {

@ ./src/main.js 5:0-28
@ multi (webpack)-dev-server/client?http://localhost:8088 webpack/hot/dev-server ./src/main.js

error in ./src/views/login.vue

Syntax Error: Unexpected token {

@ ./src/router/index.js 9:11-51
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8088 webpack/hot/dev-server ./src/main.js

error in ./src/views/common/401.vue

Syntax Error: Unexpected token {

@ ./src/router/index.js 15:11-56
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8088 webpack/hot/dev-server ./src/main.js

error in ./src/views/common/404.vue

Syntax Error: Unexpected token {

@ ./src/router/index.js 21:11-56
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8088 webpack/hot/dev-server ./src/main.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.