PHPフレームワークのVUEJS統合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引数
コンポーネント名はKebabケースの原則を尊重する必要があります。変数名を提供しない場合、Pascalcaseに変換されます
VuejsComponentメソッド
$ object -> addData ( ' name ' , true );
$ object -> addDataRaw ( ' name ' , ' true ' );adddata、adddatarawの議論
これらの2行のコードは、まったく同じVueデータを生成します
data: { "name" : true } $ object -> addMethod ( ' greet ' , ' window.alert(`Hello ${name}`); ' ,[ ' name ' ]);引数を追加します
これにより、以下のコンテンツが生成されます
methods: {
"greet" :
function ( name ) {
window . alert ( `Hello ${ name } ` ) ;
}
} $ object -> addComputed ( ' reversedMessage ' , " return this.message.split('').reverse().join(''); " );追加の引数を追加します
これにより、以下のコンテンツが生成されます
computeds: {
reversedMessage :
function ( ) {
return this . message . split ( '' ) . reverse ( ) . join ( '' ) ;
}
}これがゲッターとセッターの例です
$ 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 ' ]);追加の議論を追加します
これにより、以下のコンテンツが生成されます
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 );