【发布时间】:2021-02-14 08:04:37
【问题描述】:
我知道在Vue中父母应该通过props更新孩子,孩子应该通过events更新他们的父母。
假设这是我的父组件.vue 文件:
<template>
<div>
<my-child-component :category="category"></my-child-component>
</div>
</template>
<script>
export default {
data: {
return {
category: 'Test'
}
}
}
</script>
当我更新这个组件中的category数据时,它也会更新my-child-component中的category props。
现在,当我想在 Laravel 中使用 Vue 时,我通常使用内联模板并将值从刀片直接传递给我的组件(例如,https://stackoverflow.com/a/49299066/2311074 也建议)。
所以上面的例子我的my-parent-component.blade.php 可能看起来像这样:
@push('scripts')
<script src="/app.js"></script>
@endpush
<my-parent-component inline-template>
<my-child-component :category="{{ $category }}"></my-child-component>
</my-parent-component>
但是现在my-parent-component 不知道category 的数据。 category基本上只有孩子知道,家长和孩子之间没有任何交流。
如何在不中断父子通信的情况下从刀片传递数据?
【问题讨论】:
标签: vue.js laravel-5 laravel-blade