L'intégration VueJS pour les cadres PHP PHP-VueJS ajoute VueJS à tous les projets PHP , il pourrait être natif, ou même des projets PHP Framework
La façon recommandée d'utiliser cette bibliothèque utilise Composer , exécutez cette commande à partir du répertoire où est situé composer.json
composer require phpmv/php-vuejsIl gère l'insemble du script injecté, vous devez l'instancier
$ vueManager = VueManager:: getInstance ();Méthodes Vuemanager
$ vue = new VueJs ();Arguments Vuejs
Méthodes Vuejs
$ component = new VueJSComponent ( ' component-one ' );Arguments VuejsComponent
Le nom du composant doit respecter le principe du cas de kebab, si vous ne fournissez pas de nom de variable, il serait converti de nom en PascalCase
Méthodes VuejsComponent
$ object -> addData ( ' name ' , true );
$ object -> addDataRaw ( ' name ' , ' true ' );Adddata, arguments adddataraw
Ces deux lignes de code génèrent exactement les mêmes données VUE
data: { "name" : true } $ object -> addMethod ( ' greet ' , ' window.alert(`Hello ${name}`); ' ,[ ' name ' ]);AddMethod Arguments
Cela générera le contenu ci-dessous
methods: {
"greet" :
function ( name ) {
window . alert ( `Hello ${ name } ` ) ;
}
} $ object -> addComputed ( ' reversedMessage ' , " return this.message.split('').reverse().join(''); " );Arguments compromis
Cela générera le contenu ci-dessous
computeds: {
reversedMessage :
function ( ) {
return this . message . split ( '' ) . reverse ( ) . join ( '' ) ;
}
}Voici un exemple avec Getter et Setter
$ object -> addComputed (
' fullName ' ,
" return this.firstName+' '+this.lastName " ,
" this.firstName=v[0];this.lastName=v[1] " );Ce code génère ce contenu
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 ' ]);Arguments Addwatcher
Cela génère le contenu ci-dessous
watch: {
"title" :
function ( newTitle , oldTitle ) {
console . log ( 'Title change from ' + oldTitle + ' to ' + newTitle )
}
}Ce sont toutes les méthodes disponibles pour exécuter une fonction à un cycle de vie donné
Tous les crochets fonctionnent de la même manière, l'exemple en dessous peut être appliqué pour chaque crochet
Croche les arguments
$ object -> onCreated ( " console.log('Page has been created !'); " );Cela génère le contenu ci-dessous
created:
function ( ) {
console . log ( 'Page has been created !' ) ;
}Arguments supplémentaires, addglobaldirecteurs
$ object -> addDirective ( ' focus ' ,[ ' inserted ' => " el.focus() " ]);Cela génère le contenu ci-dessous
directives: {
focus : {
inserted :
function ( el , binding , vnode , oldVnode ) {
el . focus ( )
}
}
} $ vueManager -> addGlobalDirective ( ' focus ' ,[ ' inserted ' => " el.focus() " ]);Cela génère le contenu ci-dessous
Vue . directive ( 'focus' , {
inserted :
function ( el , binding , vnode , oldVnode ) {
el . focus ( )
}
} ) ;AddFilter, AddGlobalFilter Arguments
$ object -> addFilter (
' capitalize ' ,
" if(!value){ "
. " return ''; "
. " } "
. " value = value.toString(); "
. " return value.charAt(0).toUpperCase() + value.slice(1); " ,
[ " value " ]);Cela génère le contenu ci-dessous
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 " ]);Cela génère le contenu ci-dessous
Vue . filter ( 'capitalize' ,
function ( value ) {
if ( ! value ) { return '' ; }
value = value . toString ( ) ;
return value . charAt ( 0 ) . toUpperCase ( ) + value . slice ( 1 ) ;
} ) ;addComponent, addGlobalComponent, importcomponentObject arguments
$ component = new VueJSComponent ( ' component-one ' );
$ component -> addData ( ' framework ' , ' ubiquity ' );
$ vue -> addComponent ( $ component );Cela génère le contenu ci-dessous
components: { "component-one" : ComponentOne } $ component = new VueJSComponent ( ' component-one ' );
$ component -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> importComponentObject ( $ component );Cela génère le contenu ci-dessous
const ComponentOne = {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ; $ component = new VueJSComponent ( ' component-one ' );
$ component -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> addGlobalComponent ( $ component );Cela génère le contenu ci-dessous
Vue . component ( 'component-one' , {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ) ;AddMixin, AddGlobalMixin Argument
$ mixin = new VueJSComponent ( ' mixin-one ' );
$ mixin -> addData ( ' framework ' , ' ubiquity ' );
$ vue -> addMixin ( $ mixin );Cela génère le contenu ci-dessous
mixins: [ MixinOne ] $ mixin = new VueJSComponent ( ' mixin-one ' );
$ mixin -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> addGlobalMixin ( $ mixin );Cela génère le contenu ci-dessous
Vue . mixin ( {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ) ;addglobalextend, étend l'argument
$ component = new VueJSComponent ( ' component ' );
$ componentOne = new VueJSComponent ( ' component-one ' );
$ componentOne -> addData ( ' framework ' , ' ubiquity ' );
$ componentOne -> extends ( $ component );
$ vueManager -> addGlobalComponent ( $ componentOne );Cela génère le contenu ci-dessous
extends: "Component" $ extend = new VueJSComponent ( ' extend-one ' );
$ extend -> addData ( ' framework ' , ' ubiquity ' );
$ vueManager -> addGlobalMixin ( $ extend );Cela génère le contenu ci-dessous
Vue . extend ( {
data :
function ( ) {
return { framework : "ubiquity" }
}
} ) ;AddGlobalObserable Arguments
$ vueManager -> addGlobalObservable ( " state " , [ " count " => 0 ]);Cela génère le contenu ci-dessous
const state = Vue . observable ( { count : 0 } ) ; Pour activer Axios
$ vueManager -> setAxios ( true );Pour activer les setInheritAttrs
$ component -> setInheritAttrs ( true );Arguments SetModel
$ component -> setModel ( ' checked ' , ' change ' );argument addvue
$ vueManager -> addVue ( $ vue );