javascript - 访问 Vue 模板中的所有 Laravel 路由
问题描述
我基本上是在尝试使用 Laravel 中的 Vue 创建某种动态表。我已成功创建表并通过 jquery 的$.getJSON
方法获取数据。我真的很想在表格中有一个链接,它可以通过使用 Laravel 的方法指向一个 URL,route()
因为我有许多不同的路由我想使用。
这种情况下的示例是该表包含所有用户的列表,我希望每个用户都有一个查看用户链接。但是我无法访问route()
Vue 组件内部的 Laravel。
让这个问题成为一个非常简短的问题:除了向模板上的属性字段添加单个路由之外,还有什么方法可以访问 Laravel 拥有的所有路由,如下所示:
<user-table-component dataRoute="{{ route('datatable.users') }}">
</user-table-component>
我愿意就如何以另一种方式解决此问题提出建议。另外,这里是模板:
<template>
<table>
<thead>
<tr>
<td v-for="header in json.headers" :key="header">{{ header }}</td>
</tr>
</thead>
<tbody>
<tr v-for="user in json.rows.data" :key="user">
<td><a href="THIS WOULD BE AN VIEW USER LINK">{{ user.name }}</a></td>
<td>{{ user.email }}</td>
<td>{{ user.created_at }}</td>
</tr>
</tbody>
</table>
</template>
<script>
module.exports = {
name: 'user-table-component',
props: ['dataroute'],
data: function(){
return {
json: []
}
},
// This is auto-run when the Vue app is booted up
mounted() {
// Closure to accept component in the callback below
var self = this;
$.getJSON(this.dataroute, function(json) {
self.json = json;
});
}
}
</script>
解决方案
用这个
https://github.com/tighten/ziggy
然后在Javascript中你可以使用route('route.name')
推荐阅读
- excel - 从列中拆分单词并根据数组中的条件重新加入
- sql - 函数 PL/SQL ORACLE
- android - 如何从 Kotlin 的 recyclerview 获取 Checkbox isChecked 数据
- java - JAVA 正则表达式识别值并对路径参数进行分类
- angular - Angular 11(或 9+)I18n 在启动时设置语言环境
- java - 具有非 void 返回值的方法的 Java Spring 异步异常处理
- activemq - 如何通过命令行获取 Apache ActiveMQ 的统计信息
- node.js - Connect-mongodb-session: TypeError: Cannot read property 'Store' of undefined (mongodb, nodejs, connect-mongodb-session)
- powershell - 不同计算机语言的日期转换出错
- c# - 反序列化列表
使用运行时的类型