I am trying to load a component with Vue-Router, besides loading the required URL it does not change what is being displayed. If I access the URL path manually it displays the component correctly. I am also using Laravel and because of this, I inserted the following line on web.php so Vue-Router can be responsible for handling the routes.
Route::get('/{any}', 'SinglePageController#index')->where('any', '.*');
Watch here the error (IMGUR - Gif):
App.js
import './bootstrap';
import Vue from 'vue';
import Vuetify from 'vuetify';
import axios from 'axios';
import VueCookie from 'vue-cookie';
import router from '#/js/routes.js';
import App from '#/js/views/App';
Vue.use(Vuetify);
Vue.use(VueCookie);
const app = new Vue({
el: '#app',
router,
render: h => h(App)
});
export default app;
routes.js
import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '#/js/views/Home';
import About from '#/js/views/About';
import Exames from '#/js/views/Exames/Exames';
import checkAuthentication from '#/js/utils/check-authentication.js';
import getStaffData from '#/js/utils/get-staff-data.js';
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: About
},
{
path: '/exames',
name: 'exames',
component: Exames
}
]
});
//router.beforeEach(checkAuthentication);
//router.beforeEach(getStaffData);
export default router;
Home.vue
<template>
<div>
<h1>Página de Início</h1>
</div>
</template>
Exames.vue
<template>
<div>
<v-layout d-flex align-start justify-start row fill-height>
<v-flex xs6 sm6>
<v-card>
<v-card-title primary-title>
<div>
<h3 class="headline mb-0">Kangaroo Valley Safari</h3>
<div>Located two hours south of Sydney in the <br>Southern Highlands of New South Wales, ...</div>
</div>
</v-card-title>
<v-card-actions>
<v-btn flat color="orange">Share</v-btn>
<v-btn flat color="orange">Explore</v-btn>
</v-card-actions>
</v-card>
</v-flex>
<v-flex xs6 sm6>
<v-card>
<v-card-title primary-title>
<div>
<h3 class="headline mb-0">Kangaroo Valley Safari</h3>
<div>Located two hours south of Sydney in the <br>Southern Highlands of New South Wales, ...</div>
</div>
</v-card-title>
<v-card-actions>
<v-btn flat color="orange">Share</v-btn>
<v-btn flat color="orange">Explore</v-btn>
</v-card-actions>
</v-card>
</v-flex>
</v-layout>
</div>
</template>
<script>
export default {
props: ['membro'],
data() {
return {
name: 'exames'
}
}
}
</script>
You have to load the components in a router-view, so that when route changes, the components load within that router-view component.
You can look at this codepen to see how to do that. Notice the <router-view></router-view> in Line 22
Related
I want to install ckeditor to add blog posts to my Laravel 9 mix and vue js 3 project. If I do as the ckeditor says on his page, the ckeditor will not appear unless he makes a mistake
enter image description here
App.js
require('./bootstrap');
import { createApp } from "vue";
import App from './components/App';
import router from './router'
import store from "./store/store";
import AOS from 'aos'
import 'aos/dist/aos.css'
import CKEditor from '#ckeditor/ckeditor5-vue';
const app = createApp({});
app.AOS = new AOS.init();
app.component('my-app',App);
app.use(router)
app.use(store);
AOS.init();
app.mount('#wrapper');
createApp( { /* options */ } ).use( CKEditor ).mount( /* DOM element */ );
newBlog.vue file
<script setup>
import {mapGetters} from "vuex";
</script>
<template>
<div id="app">
<form #submit.prevent>
<div class="form-row mb-4">
<label>Blog adi</label>
<div class="form-group col-md-12">
<input class="form-control w-100" v-model="blogName">
</div>
</div>
<div class="form-row mb-4">
<label>Blog yazısı</label>
<div>
<ckeditor :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
</div>
</div>
<button type="button" #click="send()" class="btn btn-primary mt-3">Redaktə et</button>
</form>
</div>
</template>
<script>
import ClassicEditor from '#ckeditor/ckeditor5-editor-classic/src/classiceditor';
import EssentialsPlugin from '#ckeditor/ckeditor5-essentials/src/essentials';
import BoldPlugin from '#ckeditor/ckeditor5-basic-styles/src/bold';
import ItalicPlugin from '#ckeditor/ckeditor5-basic-styles/src/italic';
import LinkPlugin from '#ckeditor/ckeditor5-link/src/link';
import ParagraphPlugin from '#ckeditor/ckeditor5-paragraph/src/paragraph';
export default {
name: 'app',
data() {
return {
blogName: '',
editor: ClassicEditor,
editorData: '<p>Content of the editor.</p>',
editorConfig: {
// The configuration of the editor.
}
};
}
}
</script>
Export
enter image description here
How do I pass a slot or a prop to a layout component in inertia?
For example, heres a ForgotPassword component:
<template>
<slot name="title">Forgot Password</slot>
Forgot pw stuff goes here...
</template>
<script>
import CardLayout from "#/Layouts/CardLayout";
export default {
layout: CardLayout,
}
Here is the CardLayout component:
<template>
<h1>{{ $slots.title }}</h1>
<slot/>
</template>
Nothing shows up inside the h1 tag...
Adding this here as the solution above does not work. You can pass data to the Layout component by setting a prop value
layout: (h, page) => h(Layout, { somePropDataDefinedInLayout: value }, () => page)
// CardLayout
<template>
<h1><slot name="title" /></h1>
<slot />
</template>
// ForgotPassword
<template>
<template #title>Forgot Password</template>
Forgot pw stuff goes here...
</template>
I'm trying to pass an event to the parent component from the child component. I'm new to this and stuck at it. Basically, it is a dashboard having just a side panel and displaying area. The displaying area is in the dashboard template itself without a separate component.
This is my code for the dashboard.vue
<template>
<app-layout title="Dashboard">
<template #header>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Dashboard
</h2>
</template>
<div class="h-screen bg-white overflow-hidden shadow-xl grid grid-cols-5">
<click/>
<div>
{{msg}}
</div>
</div>
</app-layout>
</template>
<script>
import AppLayout from '#/Layouts/AppLayout.vue'
import click from '#/Components/click.vue'
export default {
components: {
AppLayout,
click,
},
data(){
return{
msg:'1'
}
},methods:{
addValue:function(){
this.msg++
}
}
}
</script>
And This is my click.vue component
<template>
<div>
<button v-on:click="add" class="border-solid font-semibold hover:bg-blue-600 hover:text-white border-b-2 w-full py-5" id="click">Click ME 1</button>
</div>
</template>
<script>
export default {
methods:{
add:function(){
this.$parent.$emit('addValue');
}
}}
</script>
I'm trying to trigger the addValue() in Dashboard.vue from Click.vue
You could use inject/provide pattern :
in root component :
methods:{
addValue:function(){
this.msg++
}
},
provide: function () {
return {
addValue: this.addValue
}
}
in grandchild component inject the method and run it from your method:
export default {
inject: ['addValue'],
methods:{
add:function(){
this.addValue();
}
}}
I am new in Nextjs I am using the swiper in my component but I am getting an error and pagination navigation and swiper CSS is not found this code working fine in Reactjs when I use this code in Nextjs I am getting an error how to import this CSS in Nextjs
enter
import React, { useState } from "react";
import LandingItem from "../landing-item/landing-items-component";
import styles from "./landing-items-preview-styles.module.scss";
import SwiperCore, { Navigation } from "swiper";
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css/components/navigation/navigation.scss";
import "swiper/css/components/pagination/pagination.scss";
import "swiper/css/swiper.css";
function LandingItemsPreview({ otherProps: { id, items, name } }) {
return (
<div className={`${styles.landing_items_preview}`}>
<div className={`${styles.header}`}>
<h1 className={`${styles.title}`}>{`Top ${name}`}</h1>
<button className={`${styles.view_all}`}>View All</button>
</div>
<div className={`${styles.swiper_main_container}`}>
<span
disabled={isBeginning}
className={`${styles.custom_swiper_button} ${styles.skewed}`}
onClick={goback}
>
➜
</span>
<Swiper>
{items.map(({ id, ...otherProps }) => (
<SwiperSlide key={id} className={`${styles.TopRestaurant_slides}`}>
<LandingItem {...otherProps} />
</SwiperSlide>
))}
</Swiper>
<span
disabled={isEnd}
className={`${styles.custom_swiper_button}`}
onClick={goNext}
>
➜
</span>
</div>
</div>
);
}
export default LandingItemsPreview;
here
They are available in compiled format, try this:
import 'swiper/components/navigation/navigation.min.css';
Try importing "navigation.min.css" instead "navigation.scss"
I'm trying to build a website with Laravel 5.4, Laravel Mix, VueJS and Materialize-css.
VueJS and jQuery are shipped with Laravel, so nothing to do there. All created components work as they should work.
I installed Materialize-css via npm following the instructions on the website.
But now I get an error when I try to implement a sidenav which should fly in on button-click. Other materilizecss-components (like Toasts, Collapsibles) work fine.
Here is my bootstrap.js which loads jQuery, Materialize-css etc:
window._ = require('lodash');
window.$ = window.jQuery = require('jquery');
require('bootstrap-sass');
require('materialize-css');
import 'materialize-css/js/materialize.js';
import 'materialize-css/bin/materialize.js';
window.Vue = require('vue');
window.axios = require('axios');
window.axios.defaults.headers.common = {
'X-CSRF-TOKEN': window.Laravel.csrfToken,
'X-Requested-With': 'XMLHttpRequest'
};
And this is my adminarea.js, which contains all the stuff I need for my admin-area:
require('./bootstrap');
Vue.component('example', require('./Vue/components/Example.vue'));
Vue.component('admindashboard', require('./Vue/components/Admindashboard.vue'));
Vue.component('test', require('./Vue/components/Test.vue'));
Vue.component('adminnav', require('./Vue/components/Adminnav.vue'));
const app = new Vue({
el: '#app',
data: {
title: 'Admindashboard'
},
methods: {},
mounted() {
console.log('Da bin ich!');
Materialize.toast('I am a toast!', 4000);
}
});
My Adminnav-component:
<template>
<div>
<ul id="slide-out" class="side-nav">
<li><div class="userView">
<div class="background">
<img src="">
</div>
<img class="circle" src="">
<span class="white-text name">John Doe</span>
<span class="white-text email">jdandturk#gmail.com</span>
</div></li>
<li><i class="material-icons">cloud</i>First Link With Icon</li>
<li>Second Link</li>
<li><div class="divider"></div></li>
<li><a class="subheader">Subheader</a></li>
<li><a class="waves-effect" href="#!">Third Link With Waves</a></li>
</ul>
Sidenav
</div>
</template>
<script>
export default {
mounted() {
console.log('Mainnav mounted');
},
methods: {
openSidenav(){
$('.button-collapse').sideNav('show');
}
}
}
</script>
And the html-file:
<body>
<div id="app">
<adminnav></adminnav>
#yield('content')
</div>
<script src="{{ asset('assets/js/adminarea.js') }}"></script>
</body>
jQuery itself works, too. I don't know where to initialize the materilizecss-components. Any ideas?
Thanks!
Take a look at https://vuematerial.github.io/#/getting-started
You have a lot of custom components which are pretty easy to use.
If you want to stick to your implementation you have 2 options
import Materialize from 'materialize-css/js/materialize.js';
const app = new Vue({
el: '#app',
data: {
title: 'Admindashboard'
},
methods: {},
mounted() {
console.log('Da bin ich!');
Materialize.toast('I am a toast!', 4000);
}
});
or
import Materialize from 'materialize-css/js/materialize.js';
window.Materialize = Materialize;
I suggest not setting Vue to window because there is no need to do so. Same with axios. You can bind axios to the vue instance instead. Vue.prototype.$http = axios. You can make calls via this.$http.get.... after that.
Also stick with imports only rather than combining require and imports.
I've found a solution:
Instead of require('materialize-css') in adminarea.js (normally app.js in a fresh Laravel installation) I had to require('materialize-css/dist/js/materialze.js') and require('materialize-css/js/init.js').
Now everything works fine.