Skip to content

Instantly share code, notes, and snippets.

@raphaelbadia
Last active October 23, 2017 12:29
Show Gist options
  • Save raphaelbadia/4adab4e9bf5372b9c14ab5b8d25f2e5e to your computer and use it in GitHub Desktop.
Save raphaelbadia/4adab4e9bf5372b9c14ab5b8d25f2e5e to your computer and use it in GitHub Desktop.

Vue Cheat Sheet

Basic Vue structure

{{ var }} displays an escaped string.

<div class="app">
	<p>{{ title }}</p>
	<p>{{ sayHello() }}</p>
	<p><a href="{{ link }}">This link is not working: Vuejs cannot bind it.</a></p>
</div>
new Vue({
	el: '#app',
	data: {
		title: 'Hello World!',
		link: 'http://google.com'
	},
	methods: {
		sayHello: function() {
			return this.title; // returns a string
		}
	}
});

Rendering

v-bind

Tells Vuejs "Don't use the normal attribute (href), bind it

<a v-bind:href="link">Google</a>

v-once

v-once will not reload a component if it changes.

<!-- single element -->
<span v-once>This will never change: {{msg}}</span>
<!-- the element have children -->
<div v-once>
  <h1>comment</h1>
  <p>{{msg}}</p>
</div>
<!-- component -->
<my-component v-once :comment="msg"></my-component>
<!-- v-for directive -->
<ul>
  <li v-for="i in list" v-once>{{i}}</li>
</ul>

v-html

By default, Vuejs escapes html code. v-html renders html.

<p v-html="finishedLink"></p>
finishedLink: '<a href="http://google.com">Google</a>'

v-model

Title gets changed every time an input is read

<input v-model="title">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment