PHP code example of sablesoft / yii2-vue

1. Go to this page and download the library: Download sablesoft/yii2-vue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sablesoft / yii2-vue example snippets


    ...
    'components' => [
        ...
        'vueManager'   => [
            'class'      => 'sablesoft\vue\VueManager',
            'delimiters' => [ '[[', ']]' ],  // specify custom for smarty
            'isDev'      => true              // false is default
        ],
        ...
    ],

    Yii::$app->vueManager->register([

        'type' => 'instance',  // is default, use 'component' type
                               // to register vue component

        // html element id (for vue class instance):
        'id' => 'buy-number',

        // vue class instance var name:
        'jsName'  => 'buyNumber',

        // path to your vue app sources ( see details below ):
        'sourcePath'    => '@yourAlias/path/to/vueApp/sources',

        // your vue app reactive data:
        'data' => [
           'routes'  => $yourRoutes,
           'flags'   => $someCustomFlags,
           'model'   => $yourModel->getAttributes(),
           ...
        ],

        // use jsExpression wrapper for short js
        // for long js use sourcePath ( see below ):
        'created' =>
            new JsExpression( "function() { console.log('Vue created!')}" ),

        // also you can use string value as path to your js:
        'computed' => '@yourAlias/path/to/computed.js',

        // for vue 'component' type:
        'props' => [...],
        'template' => '<li><span>...</span></li>'

    ]);
js
    (function(){
        return {
            fieldA : 'fieldValue',
            fieldB : function(){...},
            ...
        }
    })();