I want to load the template
for a VueJS ponent dynamically. I'd like to make an AJAX call using jQuery, and whatever the server returns should be the template
of the VueJS ponent. Here's a simplified version of the code with the AJAX call removed since it's irrelevant where the data is ing 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?
I want to load the template
for a VueJS ponent dynamically. I'd like to make an AJAX call using jQuery, and whatever the server returns should be the template
of the VueJS ponent. Here's a simplified version of the code with the AJAX call removed since it's irrelevant where the data is ing 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?
Share Improve this question edited Jan 27, 2015 at 13:56 nils 27.3k6 gold badges73 silver badges81 bronze badges asked Jan 16, 2015 at 16:01 NightwolfNightwolf 4,6892 gold badges23 silver badges36 bronze badges1 Answer
Reset to default 5You could use v-partial
in your template. And when you've loaded the partial, you can register it via Vue.partial()
. The {{ partial }}
value is then replaced, thus rendering the new partial.
BoardFeed = Vue.extend
template: '<div v-partial="{{ partial }}">This should be replaced</div>'
partials: {"beforeLoad": "<div>This should be replaced</div>"}
data: ->
return {items: null, partial: "beforeLoad"}
created: ->
Vue.partial("afterLoad", "<div>Template returned from server, what I really want</div>")
@partial = "afterLoad"
(and excuse any coffee-script errors, I'm not very familiar with it)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744886532a4599154.html
评论列表(0条)