Skip to content

Instantly share code, notes, and snippets.

@pedrozath
Last active September 16, 2018 14:56
Show Gist options
  • Save pedrozath/341ab8a84567c50d88252b446fcbab29 to your computer and use it in GitHub Desktop.
Save pedrozath/341ab8a84567c50d88252b446fcbab29 to your computer and use it in GitHub Desktop.
class ComponentsController < ApplicationController
def show
render html: view_context.component(params[:component], html_attrs: JSON(params[:attributes]))
end
end
Vue.component('content-loader', {
props: ['content-url', 'props'],
data() {
return {
template: undefined
}
},
watch: {
contentUrl(new_value){
this.updateTemplate(new_value)
}
},
methods: {
updateTemplate(url){
if(!url) return
axios.get(url, {
params: {
remote: true,
attributes: this.props
},
})
.then(response => this.template = response.data)
}
},
mounted(){
this.updateTemplate(this.contentUrl)
},
created() {
this.$options.render = function(createElement){
return createElement(
this.template
? Vue.compile(this.template)
: this.$vnode.data.inlineTemplate
)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment