Skip to content

Instantly share code, notes, and snippets.

@edwardkenfox
Last active March 21, 2018 16:01
Show Gist options
  • Save edwardkenfox/e7c7df7d56110df862509cf5e9a753ef to your computer and use it in GitHub Desktop.
Save edwardkenfox/e7c7df7d56110df862509cf5e9a753ef to your computer and use it in GitHub Desktop.
Vue on rails sample
<div id="user_info">
</div>
<script>
javascript_tag do
<<-JS
window.User = window.User || #{@json_from_controller_or_wherever.html_safe};
JS
end
</script>
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<%= render "user_info" %>
<script src="./user_info.js"></script>
</body>
</html>
new Vue({
data() {
return {
user: {
first_name: '',
last_name: '',
}
}
},
template: `
<div>
<h1 v-text="fullName"></h1>
</div>
`,
computed: {
fullName() {
return `${this.user.first_name} ${this.user.last_name}`
}
},
created() {
if (window.User) {
this.user = window.User
}
}
}).$mount('#user_info')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment