ورقة غش Vue.js
Vue هو إطار عمل JavaScript تدريجي لبناء واجهات المستخدم. على عكس أطر العمل المتكاملة الأخرى، تم تصميم 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({ ... }) // إنشاء المكونات
Vue.nextTick(() => {...})
Vue.set(object, key, val) // تفاعلي
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, // استبدال العنصر (افتراضي true)
// دورة الحياة
created () {},
beforeCompile () {},
compiled () {},
ready () {}, // يتم إدخال $el للمرة الأولى
attached () {},
detached () {},
beforeDestroy () {},
destroyed () {},
// الخيارات
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>