【问题标题】:Vue JS button click redirecting to 404Vue JS按钮单击重定向到404
【发布时间】:2021-10-30 15:08:39
【问题描述】:

我的 laravel/Vue 应用程序中有以下组件。

当用户点击此按钮时,我想将他们发送到privacy blade(sample.site/privacy-policy)

<template lang="">
  <div class="verbatimGameLayout__footer">
    <FeedbackButton label="Vie privée" :onClick="goToFeedback" />
    <SaveButton label="sauvgarder" />
  </div>
</template>

export default {
  components: {
    FeedbackButton
  },
  methods: {
    goToFeedback() {
      window.location = "/privacy-policy";
    }
  }
};

我的路线如下web.php

Route::get('/privacy-policy', 'SecurityImplementationController@privacy');

当我尝试访问 URL 时,它一直给我一个 404 错误...

以下是与上述问题相关的控制器(SecurityImplementationController.php)方法

public function privacy() {
        return view('privacy');
    }

【问题讨论】:

  • ``` Route::get('/privacy-policy', 'SecurityImplementationController@privacy'); ``` 为什么你的路由开头有斜线?你试过删除它吗?
  • 你应该在你的函数中使用:window.location.href=...
  • 不,它也不起作用
  • 在 vue.js 中你应该绑定 onclick 像这样 "v-on:click" 而不是 ':onClick'

标签: laravel vue.js routes


【解决方案1】:

你为什么不清理你的路由缓存并检查一下

php artisan route:clear

php artisan route:cache

【讨论】:

    【解决方案2】:

    我建议您使用vue-router 进行此类操作。

    使用vue-router,您可以轻松地设置这样的路线:

    const routes = [
      { path: '/foo', component: Foo },
      { path: '/bar', component: Bar }
    ]
    

    然后你可以这样调用路由:

    this.$router.push('/bar')
    

    在文档中查看更多信息:Vue Router | Getting Started

    【讨论】:

      猜你喜欢
      • 2021-11-23
      • 2018-10-14
      • 2014-07-23
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多