How to initialize a template dynamically with the result of an ajax call
See original GitHub issueI want to load the template for a VueJS component dynamically. I’d like to make an AJAX call using jQuery, and whatever the server returns should be the template of the VueJS component. Here’s a simplified version of the code with the AJAX call removed since it’s irrelevant where the data is coming from:
BoardFeed = Vue.extend
template: '<div>This should be replaced</div>'
data: ->
return items: null
created: ->
@template = "<div>Template returned from server, what I really want</div>"
In the above example I’m using the created hook which I thought would be suitable for this, but the newer template is never rendered, only the older one.
Is it possible to achieve this?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:13 (2 by maintainers)
Top Results From Across the Web
VueJS - How to initialize a template dynamically with the result ...
I want to load the template for a VueJS component dynamically. I'd like to make an AJAX call using jQuery, and whatever the...
Read more >Javascript – VueJS – How to initialize a template dynamically ...
I want to load the template for a VueJS component dynamically. I'd like to make an AJAX call using jQuery, and whatever the...
Read more >VueJS - How to initialize a template dynamically with the result ...
Coding example for the question VueJS - How to initialize a template dynamically with the result of an ajax call-Vue.js.
Read more >Magento 2: Set Template Dynamically Using Ajax Call
1 Answer 1 · use below code in to button click · app\etc\vender\module\Controller\Ajax\Ajax.php · app\etc\vender\module\view\frontend\layout\ ...
Read more >Getting started - Developer guides - MDN Web Docs
In this article. What's AJAX? Step 1 – How to make an HTTP request; Step 2 – Handling the server response; Step 3...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I still think that’s the same situation. Have a look at this fiddle: (code is duplicated below):
@TMiguelT Ok go it!, so how do you do it for single file template syntax returned by ajax like so:
how do i make that to work with vue… I think putting a native protected runtime template compiler is something that Vue is missing and i want it to work this way coz of ide support etc. I don’t want to use webpack code splitting and the like… I want to be able to load a template through Ajax and use it in the browser.