Answer the question
In order to leave comments, you need to log in
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) ?>
<script>
var app = new Vue({
el: '#fonter',
data: {
example:<?= '\'' . $model->example . '\''?>
}
})
</script>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question