1

I'm working on a Laravel project and i use VueJS for notifications system. However, i'm a real noob in VueJS dev'. Consequently, i don't know how to print a variable as text.

Situation : System of notifications work and i would like to print the number of notifications in a bootsrap badge. So, i did this :

<i class="fa fa-bell-o" aria-hidden="true"></i>  Notifications <span id='badge' class="badge badge-info">{{notifications.length}}</span> <span class="caret"></span>

With this code in my Notification.vue file :

    <template>
    <li class="nav-item dropdown">
        <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
            <i class="fa fa-bell-o" aria-hidden="true"></i>  Notifications <span id='badge' class="badge badge-info">{{notifications.length}}</span> <span class="caret"></span>
         </a>

         <ul class="dropdown-menu" role="menu">
            <li style="text-align:center" v-for="notification in notifications">
                <a href="#" v-on:click="MarkAsRead(notification)">
                    {{notification.data.idea.name}} a été validée !<br>
                 </a>
            </li>
             <li style="text-align: center" v-if="notifications.length==0">
              Aucune notification !
             </li>
         </ul>
     </li>
</template>

<script>

    export default {
        props: ['notifications'],
        methods: {
            MarkAsRead: function (notification) {
                var data = {
                    id: notification.id
                };
                axios.post('/notification/read', data).then(response => {
                    window.location.href = "/manif/";
                });
            }
        }
    }
</script>

Finally i only see {{notifications.length}} write in the badge instead of a number...

Can you help me about this ? Thank's

1 Answer 1

3

The raw mustache tags are shown because you've used v-pre directive in the parent element, which tells Vue to not compile the element and its children:

<a id="navbarDropdown" ... v-pre> <!-- Don't use v-pre here -->
  ...
  <span ...>{{notifications.length}}</span>
</a>

Simply removing that directive should resolve the issue: demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.