Refresh the content of VueJS Resource

Resource file helper/json_new.json

{
  "content": {
    "content_body": "<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>",
    "content_nav": "",
  }
}

Vue script.js file

new Vue({
    el: 'body',

    data: {
        text: 'Lorem sss',
    },

    methods: {
        getLink: function(){
            this.$http.get('http://localhost/vuejs/helper/json_new.json').then((resp) => {

                this.$set('text', resp.data.content.content_body);

            }, (resp) => {
                console.log('error');
            })
        }
    }
})

Output: Not Displayed Properly

<a href="#" v-on:click.prevent="getLink">{{ button }}</a>

Issue: The click event is not triggering. Data cannot be retrieved.

Answer №1

Vue.resourse does not have any impact on this issue since the HTML string from JSON is not compiled.

Here is a small test based on your example:

<body>
    <a href='#' v-on:click.prevent='getLink' v-text="button"></a>
    <div v-el:sample></div>
</body>
var test = new Vue({
  el: 'body',

  data: {
    button: 'Lorem sss',
  },

  methods: {
    getLink: function(){
      var r = Math.floor(Math.random() * (4 - 1)) + 1;
      this.$set('button', ['','btn1','btn2','btn3'][r] );
    },

    getCompiled: function() {
      $(this.$els.sample).empty()
      var element = $(this.$els.sample).append("<a href='#' v-on:click.prevent='getLink'>{{ button }}</a>");
      this.$compile(element.get(0));
      $(this.$els.sample).prepend('<p>Compiled button:</p>')
    }
  },

  ready: function() {
    this.getCompiled();
  }
})

jsfidle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Minimizing switch-case statement into inactive input field (AngularJS)

While the code statement functions as intended, it may not be considered best practice due to the repetition of variables in each case of the switch statement. I am unsure of how to streamline the code or if there is an alternative to using a switch statem ...

A problem encountered in specific JavaScript code

As a newcomer to JavaScript, I have encountered an issue while trying to run this script: <html> <head> <title>Exploring javascript functionalities</title> </head> <body> <p id="demo">I ...

After props have been passed, the ReactJS ComponentWillMount() function is triggered

Can anyone explain why the child component is only rendered once, even though I pass props to it every time I click a button? Whenever I click a button that passes props to the child, the ComponentWillMount() method of the child component doesn't tri ...

Is there a problem with the way divs are being displayed when using jQuery to show the first 12 elements with the class "hide-show"?

I am encountering a problem with displaying data using the jQuery slice() and show() methods to reveal dynamically generated divs from a PHP function. The code is as follows: <style> .hide-show { display :none; } </style> <div class="c ...

How can I prevent the interpolation of "${variable}" in HTML when using AngularJS?

I need to display the string ${date} in a div element: <div>please substitute the ${date} as the tag for the name</div> The displayed content should be: please use the ${date} as the substitute tag to the name. However, the browser interpre ...

What is the best way to iterate through indexed numbers within a stdClass Object?

The desired output that I am attempting to access is as follows: stdClass Object ( [results] => stdClass Object ( [columns] => stdClass Object ( [name] => Name [id] => ...

Attempting to display my ejs template from a node server following the activation of a delete button, all without utilizing ajax

I have created a basic blog application using node.js for the backend and ejs for the frontend. Posting blogs using a web form works well by calling a post route. Now, I am facing an issue with implementing a delete button for each blog post. The current s ...

Utilizing Node, ObjectionJS, and Knex, we can establish a one-to-many relationship and retrieve the first associated row from the many

To simplify, I use two tables for a chatbox: Conversation and Message Conversations ID Status 1 open 2 open Messages Conversation ID Text Date 1 'ffff' (random date) 1 'asdf' (random date) 1 '3123123123&ap ...

The functionality of Vue .map does not apply to radio button groups

Hello, I am currently working on a Vue app that is using checkboxes for filtering options. Everything is working smoothly for selecting multiple options. However, I would like to change it so that only one option can be selected at a time, like using radio ...

Postman successfully validates the API, however, it experiences issues when run in Mocha JS

When testing my API with Postman, everything works fine. However, when I try to test the same API with Mocha JS using the same data, I am encountering errors such as "500 internal server error" and "400 bad request". I have double-checked that I am passin ...

Utilizing Protractor's advanced filtering techniques to pinpoint the desired row

I am trying to filter out the specific row that contains particular text within its cells. This is my existing code: private selectTargetLicense(licenseName: string) { return new Promise((resolve => { element.all(by.tagName('clr-dg-tab ...

Initiate the month transition event within the fomantic calendar

In my project, I have integrated the fomantic calendar and it is working properly. However, I am facing an issue when it comes to changing the month. Is there a specific event for month changes in the fomantic calendar? I am struggling to make it work. Tha ...

Issue with utilizing the 'multiple' prop in Vuetify for uploading files

I've been working with Vuetify to create a form that features the option for users to upload multiple files. I have successfully included the 'multiple' prop to allow this functionality, but I am encountering an issue where uploading another ...

Node.js offers a simple and efficient way to retrieve screen resolution. By using

I am trying to retrieve the screen resolution using node.js, but the code snippets provided are not working as expected. var w = screen.width; var h = screen.height; The following code also did not work for me: var w = window.screen.width; var h = windo ...

Setting up a chat feature in a Laravel application: A step-by-step guide

Looking to Enhance My Web-Application I have been working on a web-application that utilizes: Laravel for the back-end Angular for the front-end. Milestone Achieved! I successfully implemented the entire user authentication process including: User Aut ...

Using AJAX along with the append method to dynamically add identical HTML content multiple times to a single element

Although I have successfully implemented most of the desired functionality with this JavaScript code, there is a persistent bug that is causing unnecessary duplicates to be created when appending HTML. Detecting Multiples The problem lies in the fact tha ...

Innovative functionality for adding and deleting elements in JQuery/JavaScript

Is there a way to dynamically add and remove items when the Append/Clear buttons are clicked using this code snippet? $("#btn1").click(function(){ $("ul").prepend("<li>List Item</li>"); }); $("#btn2").click(function(){ $("ul").remove ...

Is it possible to first match a named route and then a dynamic route in Express.js?

app.get('/post/create', create_post); app.get('/post/:slug', view_post); When trying to access /post/create, I expected the view_post function not to run. However, it still matches because "create" can be considered the value for :slug ...

What are the steps to implement the jQuery slide menu effect on a website?

When visiting the website , you may notice a symbol positioned in the top left corner of the site. By clicking on this symbol, a sleek div will slide out. How can this type of animation be achieved through javascript or jquery? ...

Using Javascript, when the command key is pressed, open the link in a new window

Currently, I am working on a Javascript function that opens links in a new tab only when the "command" key is pressed on an Apple computer. Here is what I have so far: $(document).on('click','a[data-id]',function(e){ if(e.ctrlKey|| ...