0

Can anyone suggest how to make an appended dynamic element clickable on VueJS?

The tooltip button is not triggering the vuejs popAlert methods.

const myVue = new Vue({
    el: '#vue',
    methods: {
        popAlert: function() {

            alert('clicked');

        }
    }
});

$(function() {

    $('#calendar').fullCalendar({
            defaultDate: '2017-10-12',
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: [
                {
                    title: 'All Day Event',
                    start: '2017-10-01'
                },
                {
                    title: 'Long Event',
                    start: '2017-10-07',
                    end: '2017-10-10'
                },
                {
                    id: 999,
                    title: 'Repeating Event',
                    start: '2017-10-09T16:00:00'
                },
            ],
            eventRender: function(event, element, view) {

                let htmlText = `<div class="ui tooltip">
                            <h3>Tooltip title</h3>
                            <button type="button" class="ui mini button" @click="popAlert">Delete</button>
                    </div>`;

                $(element).popup({
                            inline: false,
                            on: 'click',
                            exclusive: true,
                            hoverable: true,
                            html: htmlText,
                            context: '#vue',
                    });
            }
        });

});

https://codepen.io/tonoslfc/full/bomqWR/

5
  • 1
    You are mixing jquery and vue, Vue does'nt compile templates added by jquery. try using this Vue plugin instead: github.com/Wanderxx/vue-fullcalendar Commented Oct 15, 2017 at 14:04
  • @fatman the calendar works fine, its the popup semantic-ui tooltip "delete" button is calling the popAlert method Commented Oct 15, 2017 at 14:07
  • Of course, because you add the template via jquery, so Vue does not compile it, use the Vue plugin instead. In general, try to avoid mixing Jquery and vue, usually you'll find a Vue specific plugin that matches the Jquery plugin Commented Oct 15, 2017 at 14:08
  • The thing is semantic ui requires jquery :) Commented Oct 15, 2017 at 14:14
  • github.com/almino/semantic-ui-vue2 Commented Oct 15, 2017 at 14:47

1 Answer 1

2

You can wrap your htmlText inside another Vue component, copying parent methods and then $mount this component inside the popup in it's onCreate.

Look at my pen for details https://codepen.io/bsalex/pen/EwdQEy

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.