vuesax-next icon indicating copy to clipboard operation
vuesax-next copied to clipboard

[Notification] context of custom content

Open franzus5 opened this issue 3 years ago • 7 comments

Hi! I'm not sure is it bug or missing. So, if we're using Notifications with custom component - in that component we have no access to global context at all (e.g. vuex, i18n...)

franzus5 avatar Sep 30 '20 04:09 franzus5

you can give me an example in code or a codesandbox to understand better

@luisDanielRoviraContreras using your example: Main.vue

this.$vs.notification({
        color: 'success',
        duration: 'none',
        width: 'auto',
        content: NotificationCustom,
        position: 'bottom-center'
      });

NotificationCustom.vue

<template>
  <div class="con-user-example">
    <header>
      <p>
         {{ $t('notification.header') }} <!-- undefined _$t function -->
      </p>

      <vs-avatar-group max="7">
        <vs-avatar v-for="user in list" :key="user.id">
          <img :src="user.url" alt="">
        </vs-avatar>
      </vs-avatar-group>
    </header>

    <div class="content-user">
      <p>
        <b>Sally Willis</b> liked your post and <b>9</b> other users
      </p>
      <vs-button dark transparent icon>
        <i class='bx bx-chevron-right'></i>
      </vs-button>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';

export default {
  computed: {
    ...mapGetters('users', { // <-- here we're got an 'NoModuleDefinedStore', so this.$store - undefined
      list: 'getUsers'
    })
  }
}
</script>

If we do console.log(this) - we got this context for parent VsNotification component and all global $ variables are undefined

Refs: https://github.com/lusaxweb/vuesax-next/blob/master/packages/docs/.vuepress/components/Notification/user.vue

Sorry, I can't give you sandbox or something like that, because this code unreachable. And if you're using some global variables things (especial - vuex) - all UI part blocking

franzus5 avatar Sep 30 '20 09:09 franzus5

I think we could solve it with a property like self where you pass the this and thus we save the scope to use it within the notification, let me try it and let you know

I also encountered this problem, can you write more details how else did you solve it? or give a link to the sandbox. Thanks

empty333 avatar Dec 04 '20 10:12 empty333

@empty333 sorry, but I'm still waiting for new release with bugfixes

franzus5 avatar Dec 04 '20 10:12 franzus5

I have a notification about the site's use of cookies. I found a method that solves my problem at the time of the new release. Maybe this will help someone. It's not exactly elegant,but it works. I hid the close button using buttonClose: false and hung the desired method on the notification click using the onClick function. I also added clickClose: true to close the notification when clicked.

const cook = this.$vs.notification({ duration: "none", content: cookieInfo, clickClose: true, buttonClose: false, onClick: () => { this.$cookies.set('cookie_info', false) }, })

empty333 avatar Dec 04 '20 11:12 empty333

Is there any progress on this?

halilyuce avatar Oct 07 '21 00:10 halilyuce