在VUE组件中使用Laravel定义的路由

在VUE组件中使用Laravel定义的路由,laravel,vue.js,axios,laravel-blade,Laravel,Vue.js,Axios,Laravel Blade,我正在使用Laravel 6和VUE。我正在将刀片文件转换为VUE组件。blade文件包含一个表,其中包含从mysql数据库中拉入的数据行。我已经创建了一个可拖动组件,该组件显示用户,并允许我拖放行以重新排列它们,该表使用VUE插槽将html传递给我的组件。在我的索引视图中,表上有一个按钮。单击按钮后,它将转到我在Laravel中使用routes.php文件定义的/create端点/路由。我不想使用vue路由,我更喜欢保持我的laravel路由不变。我遇到的问题是,我不知道如何实现这一点,因为我

我正在使用Laravel 6和VUE。我正在将刀片文件转换为VUE组件。blade文件包含一个表,其中包含从mysql数据库中拉入的数据行。我已经创建了一个可拖动组件,该组件显示用户,并允许我拖放行以重新排列它们,该表使用VUE插槽将html传递给我的组件。在我的索引视图中,表上有一个按钮。单击按钮后,它将转到我在Laravel中使用routes.php文件定义的
/create
端点/路由。我不想使用vue路由,我更喜欢保持我的laravel路由不变。我遇到的问题是,我不知道如何实现这一点,因为我是VUE新手。有人能解释一下吗?我试过使用axios,但可能是我用错了?是否有更好的方法使用vue组件,但继续使用我在routes.php中定义的路由?多谢各位

main.blade.php

 <!-- Draggable Component -->
            <div id="app">
                <draggable table=@yield('content.main')></draggable>
            </div>
可拖动的

<template>
    <section v-bind:table="table">
        <button class="btn btn-default" @click="create()">
            <i class="fa fa-plus"></i>
        </button>
        <slot></slot>
    </section>
</template>

<script>
   export default {
       props: ['table'],
       data() {
           return {
               draggable: '',
           };
       },
       created() {
           this.draggable = this.table;
       },
       methods: {
           create() {
               axios.get(this.endpoint, {
                   UserName: this.UserName
               }).then(res => {
                   this.creating = true;
                   this.UserName = res.data.UserName
               }).catch(err => {
                   console.log("Error: " + err);
               })
           },
       },
       computed: {
           endpoint() {
               return `users/create`;
           },
       }
   };
</script>
endpoint()
中,您可以添加
window.location.protocol+“/”+window.location.host
,因此该方法将

endpoint() {
    return window.location.protocol + "//" + window.location.host + 'users/create';
},

如果你想将vue与你的laravel路线结合使用,那么将刀片和vue结合起来。嗨@jesuerswinsuarez,你能详细说明一下吗?或者提供一个例子或者给我指出正确的文档?谢谢。我在端点方法中添加了这个。但页面未重定向到/创建页面??在我的浏览器控制台中,我确实收到了一个200响应,在“网络”选项卡中的“预览”选项卡中,将显示/创建页面。但是在实际的浏览器中,没有重定向发生,因此页面不会改变。。。为什么会这样?好的,我想澄清一下,当您按下“创建”按钮时,您需要重定向到
/users/create
,并从此端点获取数据?如果我感到困惑,请原谅。我想要的是:单击按钮时,我只想重定向到/create页面。在这种情况下,您不需要调用
axios
,因为您不获取任何数据,您需要使用
window.location=window.location.protocol+“/”+window.location.host+“users/create”
我认为您也可以内联执行。在
create
方法中添加
window.location=this.endpoint()仅限
 Error: Request failed with status code 404
endpoint() {
    return window.location.protocol + "//" + window.location.host + 'users/create';
},