0

I have the next component, which is inside a modal tag. When clicking, the modal opens with the content fetched from said url.

<modal>
<laravel-view :url="'{{ '/post/view/' . $comment->source_id }}'"></laravel-view>
</modal>

It is defined here:

Vue.component('laravel-view',{
  template: '#laravel-view.vue-template',
  data(){
    return {
      viewHtml: null
    }
  },
  props: [
    'url'
  ],
  mounted() {
    this.loadPost(this.url)
  },
  methods: {
    loadPost(viewUrl){
      var self = this;
      $.get( viewUrl, function( htmlString ) {
        var compiled = Vue.compile('<div>' + htmlString + '</div>');
        self.viewHtml = htmlString;
      });
    }
  }
});

And the template, from a blade file:

<script type="text/x-template" id="laravel-view" class="vue-template">
    <div class="view-wrapper" v-html=viewHtml>
    </div>
</script>

When you click the laravel-view component, the modal opens (which is another component), and the content displayed would be the one it'd fetch from the link. This is the view returned from a controller with the information get from above:

<div>
    <div class="post" style="text-align: center;">
        <img src="{{ $post->image }}" style="margin: auto;" />
        <p>
            <h1 >{{ $post->title }}</h1>
            {{ $post->caption }}
        </p>
    </div>
    <div class="post-comments">
        <div class="post-content">
        @foreach( $post->comments as $comment )
            <div class="comment activity-box-w" id="{{$comment->post_id}}">
                <div class="activity-box" style="align-items: normal">
                    <div style="margin-top: 5px">
                         <div class="activity-avatar" style="background-image: url({{ asset($comment->image) }}); float: left;">
                        </div>      
                    </div>

                  <div class="activity-info">
                    <div class="activity-role">
                      {{ '@' . $comment->username }}
                    </div>
                    <div class="ellipsis">
                        <div>
                            <p class="activity-title">{{ $comment->comment }}</p>
                        </div>
                    </div>
                  </div>
                  <div class="time">
                    {{ \Carbon\Carbon::parse($comment->created_at)->toDateTimeString() }}
                  </div>
                </div>
            </div>
        @endforeach
        </div>
        <div class="post-pub" style="width: 100%;padding-top: 10px; margin-left: 25%;">
            <form style="width: 100%:">
                <textarea rows="1"></textarea>
                <button type="button" class="btn-primary btn-s" v-on:click="commentPost">Send</button>
            </form>
        </div>
    </div>
</div>

I've defined the method on both.js files (not that I need it on both; only to know where in the world it is triggered, assuming it does) and the event never triggers. I made sure the button worked by changing its type to "submit" and clicking it (which, reloaded the page). Still, the problem persists. How can I make this work?

1 Answer 1

1

To anyone interested, and hopefully this could be of use to someone experiencing the same problems, what happens is that:

As far as I could understand, the components were being re-rendered when they got the data from the source; yet, it didn't include the script again!, which, was the reason that the button wasn't responding at all. To solve this issue. I had to include it within the first blade file like this:

<laravel-view :url="'{{ '/post/view/' . $comment->source_id }}'"></laravel-view>
    <div class="post-pub" style="width: 100%;padding-top: 10px;">
        <form style="width: 100%:">
            <textarea rows="1" v-model="postComment" id="postCommentTextArea"></textarea>
            <button type="button" class="btn-primary btn-s" @click="comment({{ $comment->id }})">Send</button>
        </form>
    </div>
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.