javascript - VueJS/Laravel - 在 Laravel 和 Vue 之间共享 props
问题描述
我已经定义了一个EditorNavigation.vue
这样的组件:
<template>
<div>
<ul>
<li v-bind:class="{'is-active':(active === field.id)}" v-for="field in fields">
<a :href="'/streams/' + stream_token + '/fields/' + field.id">{{field.name}}</a>
</li>
</ul>
<div>
</template>
<script>
export default {
props: ["fields", "active", "stream_token"],
created() {
this.fields = JSON.parse(this.fields);
this.active = JSON.parse(this.active);
this.stream_token = JSON.parse(this.stream_token);
}
};
</script>
正如您在我的组件中看到的,我需要三个变量:
- 字段(所有字段的数组)
- 特定资源的唯一令牌
- 当前活动的字段 id(所以我可以设置
is-active
类)。
在我的 Laravel 视图文件中,我使用如下组件:
show.blade.php
<editor-navigation fields="{{ json_encode($stream->fields) }}" active="{{ json_encode($field->id) }}" stream_token="{{ json_encode($field->stream->token) }}"></editor-navigation>
所以上面的代码工作正常,但是感觉有点“混乱”——因为我需要editor-navigation
在很多页面中使用该组件,我想知道一旦我需要另一个变量发送给它会发生什么——我必须更新它在所有地方。
解决方案
推荐阅读
- python - 是否可以在 python 的 drawcontour 中为特定区域着色?
- python - 在 discord.py-rewrite 中将 Dm 发送给用户命令
- esp32 - 在 ESP32 中运行主程序时如何通过 wifi 接收消息?
- libtool - 使用选项 -L 链接时 libtool 找不到 la
- amazon-web-services - 在 Hadoop Map-Reduce 中,reducer 的输出是一次写一行吗?
- r - 将多个函数映射到 R 中的字符串向量的最有效方法是什么?
- scala - 环境单子中环境一词的意义
- css - r闪亮调用css文件
- c - c 程序 - netpay 的说明符错误(打印行)和冲突类型
- python - 使用通配符选项的 Python 搜索日志