0

I am new in Vue, and I have component (id="apartments"), in which I am getting content from another resources/views file, the code which I have used for adding html is:

 plansHtml = '<a href="{{ $plans[0]['href'] }}" v-on:click="testfunction();"></a>';//This is the html which I am getting from Ajax, and in this html I have used v-on:click
 activePlanContainer.html(plansHtml);

And the code in my Js file is:

var appApartments = new Vue({
    el: '#apartments',
    methods: {
        testfunction: function() {
            console.log('Test function called');
        }
    }
});

Please let me know what I am doing wrong, I have also tried v-on:click-native="testfunction();" but this also didn't worked. Thanks in advance

5
  • Try v-on:click.prevent Commented Oct 30, 2018 at 9:48
  • Possible duplicate of Vue Components and AJAX loaded HTML content Commented Oct 30, 2018 at 9:53
  • I have tried both above solutions and both not working. Commented Oct 30, 2018 at 10:21
  • try: @click.native="testfunction(); for me this was working Commented Oct 30, 2018 at 11:26
  • You need to make sure your Vue code executes after you inject the Ajaxed code or it will never be parsed by Vue. Commented Oct 30, 2018 at 13:58

1 Answer 1

0

Maybe you have two question here

  • Nothing in your <a></a> tag from your code
  • If you use native javaScript or jQuery to create Dom element, vue can't listen it(this means that the syntax of vue cannot be used.)

or your can provide more code for us to solve your problem

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

2 Comments

May be some compliation is required after adding html?
You need to use vue create DOM element , maybe you can provide all code that about createit

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.