我有一个带有vuejs2支持的Laravel应用程序。我在vuejs部分使用路由器组件。如何将类似会话的数据从laravel发送到vuejs模板。在刀片模板中,我使用<router-view ></router-view>调用vue路由器组件。如何添加数据。

感谢帮助!

最佳答案

您要使用vuejs路由器组件加载的页面,在该页面的页脚部分添加脚本。在使用router push命令后,请刷新整个页面。

保留一个标志,如:loading。首先,将其设置为true以查看一些初始消息,然后在收到axios响应时将其设置为false。根据此标志,显示您从axios响应获取的数据。当然,在获得axios响应后,更新初始声明的数据。
例:

<script>
export default {
        data(){
            return {
                loading:true,
                // Others Data
            }
        },
        methods:{
            function_name (){
                this.$router.push('/');
                window.location.reload();
            }
        },
        mounted() {
            var _this = this;
            axios.get('/data').then(function (response) {
                //others data update
                _this.loading=false;
            });
        }
    }
</script>

10-04 21:47
查看更多