Last active
March 21, 2018 16:01
-
-
Save edwardkenfox/e7c7df7d56110df862509cf5e9a753ef to your computer and use it in GitHub Desktop.
Vue on rails sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="user_info"> | |
</div> | |
<script> | |
javascript_tag do | |
<<-JS | |
window.User = window.User || #{@json_from_controller_or_wherever.html_safe}; | |
JS | |
end | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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