简体   繁体   English

Vue路由器道具在页面刷新时未更新

[英]Vue router props not updating on page refresh

Using latest laravel / Vue 使用最新的laravel / Vue

I have a vue router set as follows 我有一个vue路由器,设置如下

const routes = [
{
    path: '/constructionprojects/:id/details',
    name: 'details',
    component: require('./components/construction/ConstructionProjectDetails.vue'),
    props: true,
},

const router = new VueRouter({
    mode: 'history',
    routes, // short for `routes: routes`
});

const app = new Vue({
    //add router to app
    router,
    el: '#app',
    components: {
      checklist: require('./components/roofing/common/Checklist.vue'),
    },
});

And This all works great, but I need to be able to visit the route and have the component load, so I built a catch all in laravel to help with this as follows 而且这一切都很好,但是我需要能够访问路线并加载组件,因此我在laravel中建立了一个catch来帮助解决此问题,如下所示

Route::get('/constructionprojects/{project}/{wild}', 'Construction\ConstructionProjectController@show')->middleware('role:admin|op|ar|cdir|cpm')->where('wild', '.*');

And this works, if some one visits the url specified in the router or does a page refresh it works...kind of it loads the page correctly but none of the params passed through the router links work. 如果有人访问了路由器中指定的URL或进行页面刷新,则可以正常工作...其中的某种类型可以正确加载页面,但是通过路由器链接传递的所有参数均不起作用。 Router link set as such in a blade file.... 路由器链接在刀片文件中设置为...。

router-link :to="{ name: 'details', 
    params: {
      id: {{ $project->id }},
      user: {{ Auth::user()->load(['roles']) }},
}}">Project Details</router-link>

<transition name="slide-fade">
    <router-view :key="$route.fullPath"></router-view>
</transition>

Now my question is as follows how come when visitng the base page then clicking the router link everything works fine, as opposed to visitng the url and it routes to the correct spot but it wont grab the user param? 现在我的问题如下:当访问​​基本页面然后单击路由器链接时,一切正常,而不是访问url并路由到正确的位置,却无法抓住用户参数,这是怎么回事? Is there a way to retroactively load those params on page refresh or url vist? 有没有办法在页面刷新或URL上追溯加载这些参数?

assuming that you are using .blade file extension for your view . 假设你正在使用.blade为您的文件扩展view

Since many JavaScript frameworks also use "curly" braces to indicate a given expression should be displayed in the browser, you may use the @ symbol to inform the Blade rendering engine an expression should remain untouched. 由于许多JavaScript框架还使用“大括号”来指示应在浏览器中显示给定的表达式,因此您可以使用@符号来通知Blade渲染引擎表达式应保持不变。

maybe you could do it like this: 也许您可以这样做:

router-link :to="{ name: 'details', 
params: {
  id: @{{ $project->id }},
  user: @{{ Auth::user()->load(['roles']) }},
}}">Project Details</router-link>

you can visit this link for more information. 您可以访问此链接以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM