عبداله زرین
4 سال پیش توسط عبداله زرین مطرح شد
6 پاسخ

تغییر کامپوننت با استفاده از روت لاراول در ویو جی اس

سلام،دوستان من یه پروژه دارم که bladeهاش با کامپوننت ویو هست و برای تغییر صفحات باید کامپوننتا عوش بشه الان با router تونستم route رو عوض کنم اما فقط route عوض میشه و کامپوننت تا صفحه رفرش نشه نمیاد،کدمم اینه مشکلش کجاست؟
فایل route دهی

import about from './components/AboutComponent';
export const routes = [
    {path:'liantic/about-us',component:about}
    ];

اینم فایل js

import VueRouter from "vue-router";
import  Vue from 'vue';
import {routes} from './routes';
/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');
window.Vue = require('vue');
Vue.use(VueRouter);
const router = new VueRouter({
    mode:'history',
    routes
});
/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[۰], files(key).default))

Vue.component('example-component', require('./components/ExampleComponent.vue').default);
Vue.component('layout-component',require('./components/LayoutSliderComponent.vue').default);
Vue.component('show-event-component',require('./components/ShowEventComponent.vue').default);
Vue.component('gallery-component',require('./components/GalleryComponent.vue').default);
Vue.component('show-gallery-component',require('./components/ShowGallery.vue').default);
Vue.component('question-answer-component',require('./components/QuestionAnswerComponent.vue').default);
Vue.component('input-sans-component',require('./components/InputSansComponent.vue').default);
Vue.component('about-component',require('./components/AboutComponent.vue').default);
Vue.component('contact-component',require('./components/ContactComponent.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */
const app = new Vue({
    router,
    el: '#app'
});

اینم کامپوننتم

 <div class="owl-item active" style="width: ۲۹۶.۰۳۳px; margin-left: ۱۰px;" v-for="(event,index) in events"><div>
                            <div class="imgoptin-owl">
                                <div class="box-ribbon" v-if="soons[index] === ۱"><div class="ribbon ribbon-top-left"><span>به زودی</span></div></div>
                                <div class="box-ribbon" v-if="soons[index] === ۰" ><div class="ribbon ribbon-top-left"><span style="background-color: #۶e۶e۶e">برگزار شده</span></div></div>
                                <router-link to="liantic/about-us"><img :src="img_back+'/'+event.path" alt="Avatar" class="image"></router-link>
                                <div class="overlay">
                                    <button class="overlay-btn"><i class="fas fa-shopping-cart"></i></button>
                                    <div class="text">
                                        <h۳>{{event.title}}</h۳>
                                        <div class="icon-text"><i class="fas fa-map-marked-alt"></i><br>{{event.seat.address}}</div>
                                        <div class="icon-text"><i class="fas fa-calendar-alt"></i><br>{{event.date}}</div>
                                    </div>
                                </div>
                            </div>

ثبت پرسش جدید
TEFO
تخصص : لاراول
@tefo.ha27 4 سال پیش مطرح شد
1

برای اینکه برنامه‌تون به شکل spa در بیاد باید از router-view استفاده کنین


عبداله زرین
تخصص : Laravel VS Vue js
@mr.zarrin1994 4 سال پیش مطرح شد
0

@tefo.ha27
تگی که میخوام کامپوننت باهاش عوض بشه عکسه و router-view که میزارم واسش دیگه عکسا رو نشون نمیده


TEFO
تخصص : لاراول
@tefo.ha27 4 سال پیش مطرح شد
2

اگه تعداد کامپوننت ها کم و محدوده میتونین با v-if اونا سویچ کنین


عبداله زرین
تخصص : Laravel VS Vue js
@mr.zarrin1994 4 سال پیش آپدیت شد
0

@tefo.ha27
الان مشکل اینجاست که با اینکه روتم توی url درسته کلا وارد کنترلر و متد لاراولم نمیشه که دیتا رو بیاره و توی کنسول تمام دیتاهای کامپوننت رو ارور برمیگردونه،کدمو میزارم ببینین آیا مشکلی توی روت دادنم وجود داره؟فقط در حال حاضر روت لوکاله
روت لاراول

    Route::get('/show/event/{id}','Frontend\EventController@showEvent') -> name('show.event');

فایل روتر

import about from './components/AboutComponent';
import event from './components/ShowEventComponent';
export const routes = [
    {path:'/liantic/about-us',component:about,name:'aboutUs'},
    {path:'/liantic/public/show/event/:id',component:event,name:'event'}
    ];

کامپوننت

<router-link :to="{name:'event',params:{id:event.id}}" >
                                    <img :src="img_back+'/'+event.path" alt="Avatar" class="image">
                                </router-link>
                                <router-view></router-view>

@ali.bayat
@hesammousavi
@juza66
@Alimotreb
@hamedbaftam
@amirsharifi
ممنون میشم شما عزیزان هم راهنماییم کنین


TEFO
تخصص : لاراول
@tefo.ha27 4 سال پیش آپدیت شد
1

این مشکل به خاطر اینه اگه توی یه روت باقی بمونین و پارامترش رو فقط تغییر بدین ویو روتر اونو نمیشناسه بایه به router-view یه پارامتر اضافه کنین
فک کنم اینه

<router-view :key="$route.fullPath"></router-view>

بین $router و $route مشکوکم هردو رو امتحان کنین

پ.ن. منو منشن کردین وظیفه خودم دونستم ج بدم


عبداله زرین
تخصص : Laravel VS Vue js
@mr.zarrin1994 4 سال پیش مطرح شد
1

@tefo.ha27
خیلی ازتون ممنونم


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام