Laravel Vuejs2 отсутствует параметр для именованного маршрута - PullRequest
0 голосов
/ 21 мая 2018

Я с трудом пытаюсь изолировать ошибку консоли.

Мой код выглядит следующим образом:

myside.blade.php имеет:

<div class="nav-container">
                    <ul class="nav nav-icons justify-content-center" role="tablist">
                        <li class="nav-item">
                            <div>
                                <router-link class="nav-link text-primary" :to="{ name: 'property', params: { customerId: {{ $property_data[0]->listingId }} }}" @click.native="isVisible = !isVisible">
                                    <i class="nc-icon nc-key-25"></i>
                                    <br> Property
                                </router-link>
                            </div>
                        </li>
                        <li class="nav-item">
                            <router-link class="nav-link text-primary" :to="{ name: 'booking' }" @click.native="isVisible = !isVisible">
                                <i class="nc-icon nc-chart-pie-36"></i>
                                <br> Bookings
                            </router-link>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-primary" href="" role="tab">
                                <i class="nc-icon nc-preferences-circle-rotate"></i>
                                <br> Performance
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-primary" href="" role="tab">
                                <i class="nc-icon nc-money-coins"></i>
                                <br> Revenue
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-primary" href="" role="tab">
                                <i class="nc-icon nc-layers-3"></i>
                                <br> Integration
                            </a>
                        </li>
                    </ul>
                </div>

                <property-page :customer-Id="{{ $property_data[0]->listingId }}" v-if="isVisible"></property-page>

                <router-view></router-view>

Мой файл rout.js:

    import VueRouter from 'vue-router';

let routes = [
    {

        path: '/property/:customerId',
        name: 'property',
        component: require('./components/PropertyPage'),
        props: true

    },
    {

        path: '/booking',
        name: 'booking',
        component: require('./components/BookingPage')

    }
];

export default new VueRouter({

    routes,
    linkActiveClass: 'nav-link text-success'

});

Мой файл app.js:

import Vue from 'vue';

import VueRouter from 'vue-router';

Vue.use(VueRouter);

import router from './routes';


import PropertyPage from './components/PropertyPage.vue';

import BookingPage from './components/BookingPage.vue';

new Vue({

    el: '#root',

    router,

    data: {

        NavPrimaryClass: 'nav-link text-primary',

        NavClass: 'nav-link',

        isVisible: true

    },

    components: {

        'property-page': PropertyPage,
        'booking-page': BookingPage

    }

})

Мой файл PropertyPage.vue:

<template>
    <div>

        <div class="ajax-loader">
            <img src="/loader/ajax-loader.gif" width="300px" v-if="loading" />
        </div>

        <div v-if="propertyDataCheck">



        </div>



    </div>
</template>

<script>

    import moment from 'moment';

    import axios from 'axios';

    export default {

        props: {

            customerId: {
                type: Integer,
                required: true,
                default: 0
            }

        },

        data() {

            return {
                propertyData: [], 
                loading: false
            }

        },

        computed: {
            propertyDataCheck () {
                return this.propertyData.length;
            }
        },

        mounted() {

            this.loading = true;

            axios.get('/ajax/propertydata/' + this.customerId)
                .then(function(response) {
                    this.propertyData = response.data;
                    this.loading = false;
                }.bind(this))
                .catch(function() {
                  this.loading = false;
                }.bind(this));

        }

    }
</script>

<style>
.ajax-loader {
  position: absolute;
  left: 40%;
  top: 15%;
  margin-left: -32px; /* -1 * image width / 2 */
  margin-top: -32px; /* -1 * image height / 2 */
}
</style>

Конечный результат, aОшибка консоли, которую я потратил несколько часов, пытаясь понять, откуда она исходит.

Ошибка:

[vue-router] missing param for named route "property": Expected "customer" to be defined

Мне нужен компонент для загрузки при загрузке страницы (вне vue-router)) именно поэтому у меня есть <property-page :customer-Id="{{ $property_data[0]->listingId }}" v-if="isVisible"></property-page> теги и он привязан к методу, который переключается при щелчке по ссылке маршрутизатора (на случай, если вам интересно).

Мое понимание этой ошибки - переменная для первого канала маршрутизатора, сгенерированного из запроса к базе данных модели Laravel {{ $property_data[0]->listingId }} должна быть проверена в v-if, обернутом вокруг vue-router?Я также сделал это безрезультатно.

Любая помощь будет высоко ценится!

1 Ответ

0 голосов
/ 21 мая 2018

Верьте или нет, вам нужно использовать строгие hbml-свойства kebab-case (все строчные!) В vue-templates.Измените customer-Id на customer-id

<property-page :customer-Id=...  // does not get mapped to this.customerId
<property-page :customer-id=...  // does get mapped to this.customerId, yay!
...