Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$isAllowed('action', object) it performs twice in created, mounted hook. #43

Open
hen098 opened this issue Jun 4, 2019 · 0 comments
Open

Comments

@hen098
Copy link

hen098 commented Jun 4, 2019

Hi

I used $isAllowed with v-show.
There is a error in console because whenever created, mounted hook, it performs twice.
So, before post object receive value, post is undefined.

What should I do ?

*.vue

<template>
    <button v-show="$notice.isAllowed('update', post)" @click.prevent="$router.push({ name: `post-update-${$route.meta.type}` ,params:{'postNo':$route.params.postNo}})">update<button>
</template>
<script>
export default {
  name: 'post-detail',
  data () {
    return {
      post: {}
    }
  },
  perimeters: [
    noticePerimeter
  ]
  },
  created () {
    ajax('GET', `/posts/${this.$route.params.postNo}`, null).then(_data => {
        this.post = _data
      }).catch(_err => {
        this.$router.push({ name: `post-list-${this.$route.meta.type}` })
      })
  }
}
</script>

Perimeter

import BasePerimeter from './base-perimeter'

export default new BasePerimeter({
  purpose: 'notice',
  can: {
    read () { return this.isLogin() },
    create () { return this.isAllowed('read') },
    update (post) {
      return this.isAdmin() || this.isCreator(post)
    },
    destroy (post) { return this.isAllowed('update', post) }
  }
})

error

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant