Vue (pronounced /vjuː/, like view) is a progressive MVVM framework for building interactive user interfaces.
<script src="https://unpkg.com/vue"></script>
<div id="app">
{{ message }}
</div>
new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
<div v-bind:id="'list-' + id"></div>
v-if
<li v-for="todo in todos">
{{ todo }}
</li>
<p v-if="seen">Now you see me</p>
// Define and register a global component
Vue.component('todo-item', {
template: '<li>This is a todo</li>'
})
// Define and register a scoped component
var TodoItem = {
template: '<li>This is a todo</li>'
}
new Vue({
// ...
components: {
// only be available in parent's template
'my-component': Child
}
})
Vue.component('todo-item', {
// The todo-item component now accepts a
// "prop", which is like a custom attribute.
// This prop is called todo.
props: ['todo'],
template: '<li>{{ todo.text }}</li>'
})
Vue.component('example', {
props: {
// basic type check (`null` means accept any type)
propA: Number,
// multiple possible types
propB: [String, Number],
// a required string
propC: {
type: String,
required: true
},
// a number with default value
propD: {
type: Number,
default: 100
},
// custom validator function
propE: {
validator: function (value) {
return value > 10
}
}
}
})
<app>
<app-header></app-header>
<app-footer></app-footer>
</app>
Everything in the parent template is compiled in parent scope; everything in the child template is compiled in child scope.
React
<header className={`rui-clearfix${this._isWebview() ? ' webview' : ''}`}>
Vue
<header class="rui-clearfix" v-bind:class="classObject">
new Vue({
data: {
classObject: {
webview: this._isWebview()
}
}
}
React
Vue
_renderListingPropertiesFromData(property) {
return property.isProject ?
( <ProjectProfileCard key={property.listingId} data={property} /> )
:
( <PropertyListingCard key={property.listingId} data={property} /> );
}
<div className="rui-grid-row">
{ this._renderListingPropertiesFromData(propertyData) }
</div>
<component v-bind:is="currentView">
<!-- component changes when vm.currentView changes! -->
</component>
var vm = new Vue({
data: {
currentView: 'home'
},
components: {
ProjectProfileCard: { /* ... */ },
PropertyListingCard: { /* ... */ }
}
})