R
R
Rustam Akimov2019-10-10 20:39:53
Yii
Rustam Akimov, 2019-10-10 20:39:53

How to make reactivity in yii2?

I want to use reactivity from vue to reactively change text on the page, I display the form field like this

<?= $form->field($model, 'example', [
                            'options' => [
                                'v-model' => 'example'
                            ]
                        ])->label(false) ?>

And I output vue like this:
<script>
    var app = new Vue({
        el: '#fonter',
        data: {
            example:<?= '\'' . $model->example . '\''?>
        }
    })
</script>

But after the output, ActiveField loses v-model, and vue does not initialize example
Does anyone know how to make friends with this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DenisAlliswell, 2019-10-15
@Inogami

As far as I understood, the question is how to pass data from php to vue.js.
One of the options might be:

<?php
// Передаем данные из php
$this->registerJs("
     vueModel.example = '" . $model->example . "';
     vueModel.someOtherVariable = 123;
     vueModel.someOtherObject = " . json_encode($somePhpArray) . ";
", \yii\web\View::POS_BEGIN);
?>

// Если нужно добавить еще какие-либо данные из js
var vueModel.someJsVariable = 321;

var app = new Vue({
     el: '#fonter',
     data: vueModel,
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question