Vue.js is an open-source model–view–viewmodel front end JavaScript framework for building user interfaces and single-page applications. It was created by Evan You, and is maintained by him and the rest of the active core team members.
EXPRESSIONS Binding
I have a {{ product }}
{{ product + 's' }}
{{ isWorking ? 'YES' : 'NO' }}
{{ product.getSalePrice() }}
... Shorthand syntax ...
True or false will add or remove attribute ... If isActive is truthy, the class ‘active’ will appear
Element inserted/removed based on truthiness
{{ product }}
...
...
Toggles the display: none CSS property...
Two-way data binding v-model.lazy="..." Syncs input after change event v-model.number="..." Always returns a number v-model.trim="..." Strips whitespaceCalls addToCart method on component
Arguments can be passed <button @click="addToCart(product)">... To prevent default behavior (e.g. page reload)
... Only trigger onceThe :key is always recommended
To access the position in the array
Vue.component('my-component', {
components: {
// Components that can be used in the template
ProductComponent,
ReviewComponent
},
props: {
// The parameters the component accepts
message: String,
product: Object,
email: {
type: String,
required: true,
default: "none"
validator: function (value) {
// Should return true if value is valid
}
}
},
data: function() {
// data must be a function
return {
firstName: 'Vue',
lastName: 'Mastery'
}
},
computed: {
// Return cached values until dependencies change
fullName: function () {
return this.firstName + ' ' + this.lastName
}
},
watch: {
// Called when firstName changes value
firstName: function (value, oldValue) { ... }
},
methods: { ... },
template: '{{ message }}',
// Can also use backticks in template for multi-line
})
beforeCreate After the instance has been initialized # created After the instance is created # beforeMount Before the first render # mounted After the instance has been mounted # beforeUpdate When data changes, before the DOM is patched # updated After a data change # beforeDestroy Before the instance is destroyed # destroyed After a Vue instance has been destroyed #
Set listener on component, within its parent Inside parent component methods: { incWithVal: function (toAdd) { ... } } Inside button-counter template this.$emit( 'incrementBy', // Custom event name 5 // Data sent up to parent ) Use props to pass data into child components, custom events to pass data to parent elements.
{{ greeting }} World!
<script> module.exports = { data: function () { return { greeting: 'Hello' } } } </script> <style scoped> p { font-size: 2em; text-align: center; } </style>Component template
Use of component with data for slot
This will go in the slot
Component template
Use of component with data for slots
the main content.
Contact info