Skip to content
This repository has been archived by the owner on May 3, 2018. It is now read-only.

Vue 2 standalone Vue.compile rendering? #1266

Closed
randohinn opened this issue Oct 19, 2016 · 2 comments
Closed

Vue 2 standalone Vue.compile rendering? #1266

randohinn opened this issue Oct 19, 2016 · 2 comments

Comments

@randohinn
Copy link

So, with the introduction of Vue2, the compile function has changed a bit, thus I am having difficulties rendering things via compile

Here's my code:

Vue.compile(this.$el.outerHTML);

This is in a VueComponent, where I include some additional HTML templates from separate files via vue-resource, which I then need to render. In Vue 1.x, calling compile also caused the template to re-render, however this does not happen in Vue 2. How can I re-render with the compilefunction now?

@LinusBorg
Copy link
Member

In 2.0, the compile() function does not change the DOM. it only converts the template string into render functions.

Generally, what you should rather do, is something like this:

var tempComponent = new Vue({
  // template string here
  template: `<div><!-- whatever --></div>`
  // makes $parent work
  parent: this 
  // any props the component should receive. 
  // reference to data in the template will *not* have access the the current 
  // components scope, as you create a new component
  propsData:
  // possibly other options
}).$mount(/*element to mount to here*/)

(Sidenote: Specifically, it confuses me that you seem to want to use the current component's rendered HTML (this.$el.outerHTML) as a template? What should that achieve? the rendered HTML of a component does not contain any template markup for Vue)

@randohinn
Copy link
Author

@LinusBorg Thanks, that does sound more logical, thanks... that was easy! 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants