Neh*_*eha 1 forms laravel vue.js
我在 Vuejs 组件模板中使用表单。我不想定义完整的静态 URL。页面 URL 类似于http://example.com/en/discusses 并且表单应在http://example.com/comments提交。但使用
<form action = "comments" method ="POST">
Run Code Online (Sandbox Code Playgroud)
转到http://example.com/en/comments而不是http://example.com/comments。如何实现这一目标?先感谢您。
您可以在路由文件 (routes/web.php) 中为您的 post 路由命名:
例如:
Route::post('/comments', 'SomeController@store')->name('postComment');
Run Code Online (Sandbox Code Playgroud)
通常,您可以在刀片视图中的表单中使用命名路由:
<form action="{{ route('postComment') }}" method="POST">
</form>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您使用 Vue 组件,您可以通过 'postComment' 路由
<component post-route="{{ route('postComment') }}"></component>
Run Code Online (Sandbox Code Playgroud)
然后,接受 Vue 组件文件中的属性:
<template>
<form action="this.post-route" method="POST"></form>
</template>
<script>
export default {
props: ['post-route']
}
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8861 次 |
最近记录: |