gpt4 book ai didi

vue.js - 如何将数据传递给 Vue.js 中的路由器 View

转载 作者:搜寻专家 更新时间:2023-10-30 22:14:21 25 4
gpt4 key购买 nike

如何通过 Vue.js 中的 router-view 将数据从我的主应用程序传递到组件?我已成功从我的 API 获取数据,如下所示:

mounted() {
// console.log(model)
this.model = model;
// console.log(this.model)
}

我要传递数据的组件已经加载如下:

@section('content')
<div style="padding: 0.9rem" id="app">
<router-view name="bookBus"></router-view>
<router-view></router-view>
{{-- @{{ model }} --}}
</div>

@stop

如何将 model 数据传递给 bookBus 组件?

最佳答案

来自 https://router.vuejs.org/en/api/router-view.html

Any non-name props will be passed along to the rendered component, however most of the time the per-route data is contained in the route's params.

所以如果你想从父组件向下传递数据,而不是从路由器,它会是这样的:

<router-view name="bookBus" :model="model"></router-view>

您的 bookBus 组件需要配置一个 model prop 来接收数据,就像任何其他 prop 一样。

关于vue.js - 如何将数据传递给 Vue.js 中的路由器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49696424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com