萧十五郎

2171 经验值

问题解决了,在webpack.min.js加上
mix.webpackConfig({

output: {
    publicPath: '/'
}

});

参考的这篇文章 https://segmentfault.com/q/1010000010559150

使用vue-router 懒加载 ,初次渲染页面成功,当访问其他组建时 会向后端发送一个请求
比如 http://127.0.0.1:8000/tables/1.js ,该请求被laravel 路由劫持 渲染了页面,该怎样解决

// laravel wep.php
Route::get('/{all?}', function () {
    return view('backend');
})->where(['all' => '.*?']);

找到问题了 因为调试的时候我是刷新页面看的结果,请求是异步的,导致还没有赋值 控制台就输出结果了 感谢

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

router.beforeEach((to, from, next) => {
    if (to.meta.requiresAuth) {
        console.log(Store.state.AuthUser);
        /*
        * 此时 AuthUser.authenticated 为true
        * {__ob__: Observer}
          authenticated:true
          email:"[email protected]"
          name:"12345"
        *
        * */
        console.log(Store.state.AuthUser.authenticated);
        /*
         此时 AuthUser.authenticated 为false
        */

        if (Store.state.AuthUser.authenticated || JWTToken.getToken()) {
            return next();
        } else {
            return next({ name : 'confirm' });
        }
    }

    if (to.meta.requiresGuest) {
        if (Store.state.authenticated || JWTToken.getToken()) {
            return next({ name : 'home' });
        } else {
            return next();
        }
    }
    next();
});

export default router;

Store.state.AuthUser 有值
Store.state.AuthUser.authenticated 始终为false 不知道是什么原因 @JellyBool 有遇到这个问题吗?

评论后 提示这个错误
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "count"

发布评论后 提示这个错误 时什么问题?
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "count"

found in

---> <Comments> at /Users/shiwuhao/Documents/code/myCode/zhihu/resources/assets/js/components/Comments.vue

   <Root>

发布评论后 提示这个错误 时什么问题?

found in

---> <Comments> at /Users/shiwuhao/Documents/code/myCode/zhihu/resources/assets/js/components/Comments.vue

   <Root>