VUE Object.defineProperty will watch the update of the data.
When data change it will auto rerender the browsers.
Vue Official tutorial
Watch Data(Tree) Implementation
Angular: 1 Pull
React: Pull, onPush
vue: Push-based (single node)
Data Update Concept
j-query DOM: elements trigger data.
vue, Angular, react: data trigger events.
Vue does not support IE8 and below, because it uses ECMAScript 5 features that are un-shimmable in IE8. However it supports all ECMAScript 5 compliant browsers.
Import the Vue.js library by CDN or download it.
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script>
v-if
v-for
one-way binding
v-model
two-way binding
v-on
methods
v-bind
bind for html tag or css style
v-bind
shorthand:
v-on:
shorthand@
The "object" that currently is the parent of the function.
beforeCreate
created
beforeMount
mounted
beforeUpdate
update
beforeUnmount
unmount
ps: lifecycle-hooks
methods => Run when has been call, whatever the data is different or not.
computed => Auto run when the data update.( Detect data
, component
, props
and cached it)
watch => Usually use in RWD Ajax asynchronous call for the API data has changes. (Change data
base on watching some data
, and can get the previous/new data.)
Local Component:
new Vue({
el: "#app",
components: {
// local scope component declaring.
// register scoped component.
"my-component": {
template: '<div class="component">A custom component of Vue!</div>',
},
},
});
Global Component:
// Register for global component.
Vue.component("my-component", {
template: '<div class="component">A custom component of Vue!</div>',
});
// create a root instance
new Vue({
el: "#app",
});
new Vue({
el: "#app2",
});
Declare a component with it's data.
// register
Vue.component("my-component", {
template: '<div class="component">{{ msg }}</div>',
data: function () {
return {
// Component data need to be a function return.
// Need to return it in a minima function scope.
msg: "A child component in root VUE instance!",
};
},
});
- transfer the data from parent to child component.
- props data support type validation check.
- Avoid using the two-way data flow, it's possible to cause bugs.
- Use the
.$parent.$emit()
event to update parent node data in the one-way data flow condition.
- To organize the events into the single object.
- It can improve the process of the data updating in the complex node tree.
- It will remove the DOM and create new one.
- Use
keep alive
tag to cache the element data props.
slot
tag can compile the input data from parent.Slot
with name, if multiple slots.
- Sigle file for
App.vue
project. - Need to compile the App.vue with
web-pack
andvue-loader
.
A bundle of tools that increase develop process for Vue project.
gulp
(Task runner) vs Webpack
(module bundler)
- Download node.js and check the version
npm -v
. - Import VUE CLI
npm install -g vue-cli
.
npm run dev
will auto start up the localhost server.npm run build
will compress all the code and element todist
folder for production.