Skip to content

Instantly share code, notes, and snippets.

@colynb
Created September 28, 2016 20:59
Show Gist options
  • Save colynb/51b3cdb132ee1cc2177987de4afcfcd7 to your computer and use it in GitHub Desktop.
Save colynb/51b3cdb132ee1cc2177987de4afcfcd7 to your computer and use it in GitHub Desktop.
VueJS Server Rendering Test
<div id="app">
<ul>
<li v-for="option in options">
<span class="red">{{ option.text }}</span>
</li>
</ul>
<ul v-if="!fetched">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</div>
new Vue({
el: '#app',
created: function() {
this.fetchData()
},
methods: {
fetchData: function(cb) {
// simulate ajax call
setTimeout(function() {
this.fetched = true
this.options = [
{
text: "One"
},
{
text: "Two"
},
{
text: "Three"
}
];
}.bind(this), 1000);
}
},
data: {
fetched: false,
options: []
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.27/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
.red {
color: #f00;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment