Vue 速查表
Vue是一套用于构建用户界面的渐进式JavaScript框架。与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层,方便与第三方库或既有项目整合。
列表
<li v-for="todo in todos">
{{ todo.text }}
{{ $index }}
</li>
事件
<button v-on:click='submit'>Go</button>
组件
new Vue({
components: { app: App }
})
API接口
Vue.extend({ ... }) // creating components
Vue.nextTick(() => {...})
Vue.set(object, key, val) // reactive
Vue.delete(object, key)
Vue.directive('my-dir', { bind, update, unbind })
// <div v-my-dir='...'></div>
Vue.elementDirective('my-dir', { bind, update, unbind })
// <my-dir>...</my-dir>
Vue.component('my-component', Vue.extend({ .. }))
Vue.partial('my-partial', '<div>hi {{msg}}</div>')
// <partial name='my-partial'></partial>
new Vue({
data: { ... }
props: ['size'],
props: { size: Number },
computed: { fullname() { return this.name + ' ' + this.lastName } },
methods: { go() { ... } },
watch: { a (val, oldVal) { ... } },
el: '#foo',
template: '...',
replace: true, // replace element (default true)
// lifecycle
created () {},
beforeCompile () {},
compiled () {},
ready () {}, // $el is inserted for the first time
attached () {},
detached () {},
beforeDestroy () {},
destroyed () {},
// options
directives: {},
elementDirectives: {},
filters: {},
components: {},
transitions: {},
partials: {}
})
Vue模板
参考 vueify
// app.vue
<template>
<h1 class="red">{{msg}}</h1>
</template>
<script>
module.exports = {
data () {
return {
msg: 'Hello world!'
}
}
}
</script>
以及
<template lang='jade'>
h1(class='red') {{msg}}
</template>