يضيف تكامل Vuejs لأطر PHP PHP-VueJS VueJS إلى أي مشاريع PHP ، أو يمكن أن يكون مشاريع PHP Framework
الطريقة الموصى بها لاستخدام هذه المكتبة تستخدم Composer ، قم بتشغيل هذا الأمر من الدليل حيث يوجد composer.json
composer require phpmv/php-vuejsيدير البرنامج النصي بالكامل الذي تم حقنه ، يجب عليك إنشاء مثيل له
$ vueManager = VueManager:: getInstance ();أساليب Vuemanager
$ vue = new VueJs ();حجج Vuejs
طرق Vuejs
$ component = new VueJSComponent ( ' component-one ' );Vuejscomponent حجة
يجب أن يحترم اسم المكون مبدأ حالة الكباب ، إذا لم تقدم اسمًا متغيرًا ، فسيتم تحويل الاسم إلى PascalCase
طرق VuejsComponent
$ object -> addData ( ' name ' , true );
$ object -> addDataRaw ( ' name ' , ' true ' );adddata ، حجج adddataraw
ينشئ هذان السطران من التعليمات البرمجية نفس بيانات VUE بالضبط
data: { "name" : true } $ object -> addMethod ( ' greet ' , ' window.alert(`Hello ${name}`); ' ,[ ' name ' ]);حجج addmethod
هذا سيولد المحتوى أدناه
methods: {
"greet" :
function ( name ) {
window . alert ( `Hello ${ name } ` ) ;
}
} $ object -> addComputed ( ' reversedMessage ' , " return this.message.split('').reverse().join(''); " );حجج addComputed
هذا سيولد المحتوى أدناه
computeds: {
reversedMessage :
function ( ) {
return this . message . split ( '' ) . reverse ( ) . join ( '' ) ;
}
}هنا مثال مع Getter و Setter
$ object -> addComputed (
' fullName ' ,
" return this.firstName+' '+this.lastName " ,
" this.firstName=v[0];this.lastName=v[1] " );يولد هذا الرمز هذا المحتوى
computeds: {
fullName : {
get : function ( ) {
return this . firstName + ' ' + this . lastName
} ,
set : function ( v ) {
this . firstName = v [ 0 ] ;
this . lastName = v [ 1 ]
}
}
} $ object -> addWatcher (
" title " ,
" console.log('Title change from '+ oldTitle +' to '+ newTitle) " ,
[ ' newTitle ' , ' oldTitle ' ]);حجج AddWatcher
هذا يولد المحتوى أدناه
watch: {
"title" :
function ( newTitle , oldTitle ) {
console . log ( 'Title change from ' + oldTitle + ' to ' + newTitle )
}
}هذه كل الطرق المتاحة لتشغيل وظيفة في دورة حياة معينة
تعمل جميع الخطافات بنفس الطريقة ، يمكن تطبيق المثال الأساسي على كل خطافات
السنانير الحجج
$ object -> onCreated ( " console.log('Page has been created !'); " );هذا يولد المحتوى أدناه
created:
function ( ) {
console . log ( 'Page has been created !' ) ;
}حجج adddirective ، addglobaldirective
$ object -> addDirective ( ' focus ' ,[ ' inserted ' => " el.focus() " ]);هذا يولد المحتوى أدناه
directives: {
focus : {
inserted :
function ( el , binding , vnode , oldVnode ) {
el . focus ( )
}
}
} $ vueManager -> addGlobalDirective ( ' focus ' ,[ ' inserted ' => " el.focus() " ]);هذا يولد المحتوى أدناه
Vue . directive ( 'focus' , {
inserted :
function ( el , binding , vnode , oldVnode ) {
el . focus ( )
}
} ) ;addfilter ، حجج addglobalfilter
$ object -> addFilter (
' capitalize ' ,
" if(!value){ "
. " return ''; "
. " } "
. " value = value.toString(); "
. " return value.charAt(0).toUpperCase() + value.slice(1); " ,
[ " value " ]);هذا يولد المحتوى أدناه
filters: {
capitalize : function ( value ) {
if ( ! value ) { return '' ; }
value = value . toString ( ) ;
return value . charAt ( 0 ) . toUpperCase ( ) + value . slice ( 1 ) ;
}
} $ vueManager -> addGlobalFilter (
' capitalize ' ,
" if(!value){ "
. " return ''; "
. " } "
. " value = value.toString(); "
. " return value.charAt(0).toUpperCase() + value.slice(1); " ,
[ " value " ]);هذا يولد المحتوى أدناه
Vue . filter ( 'capitalize' ,
function ( value ) {
if ( ! value ) { return '' ; }
value = value . toString ( ) ;
return value . charAt ( 0 ) . toUpperCase ( ) + value . slice ( 1 ) ;
} ) ;AddComponent ، addglobalcomponent ، وسيطات importComponentObject
$ component = new VueJSComponent ( ' component-one ' );
$ component -> addData ( ' framework ' , ' ubiquity ' );
$ vue -> addComponent ( $ component );هذا يولد المحتوى أدناه
components: { "component-one" : ComponentOne } $ component = new VueJSComponent ( ' component-one ' );
$ component -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> importComponentObject ( $ component );هذا يولد المحتوى أدناه
const ComponentOne = {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ; $ component = new VueJSComponent ( ' component-one ' );
$ component -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> addGlobalComponent ( $ component );هذا يولد المحتوى أدناه
Vue . component ( 'component-one' , {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ) ;addmixin ، حجة addglobalmixin
$ mixin = new VueJSComponent ( ' mixin-one ' );
$ mixin -> addData ( ' framework ' , ' ubiquity ' );
$ vue -> addMixin ( $ mixin );هذا يولد المحتوى أدناه
mixins: [ MixinOne ] $ mixin = new VueJSComponent ( ' mixin-one ' );
$ mixin -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> addGlobalMixin ( $ mixin );هذا يولد المحتوى أدناه
Vue . mixin ( {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ) ;addglobalextend ، يمتد الحجة
$ component = new VueJSComponent ( ' component ' );
$ componentOne = new VueJSComponent ( ' component-one ' );
$ componentOne -> addData ( ' framework ' , ' ubiquity ' );
$ componentOne -> extends ( $ component );
$ vueManager -> addGlobalComponent ( $ componentOne );هذا يولد المحتوى أدناه
extends: "Component" $ extend = new VueJSComponent ( ' extend-one ' );
$ extend -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> addGlobalMixin ( $ extend );هذا يولد المحتوى أدناه
Vue . extend ( {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ) ;addglobalobservable الحجج
$ vueManager -> addGlobalObservable ( " state " , [ " count " => 0 ]);هذا يولد المحتوى أدناه
const state = Vue . observable ( { count : 0 } ) ; لتمكين axios
$ vueManager -> setAxios ( true );لتمكين setinheritattrs
$ component -> setInheritAttrs ( true );حجج setModel
$ component -> setModel ( ' checked ' , ' change ' );حجة addvue
$ vueManager -> addVue ( $ vue );