首页 > 其他分享 >laravel项目路由和Vue路由混用的方法

laravel项目路由和Vue路由混用的方法

时间:2022-10-11 17:03:40浏览次数:72  
标签:laravel Vue component element vue ui import 路由

 

目前laravel版本是5.8,vue是2.6,vue-router是3.5.1
这里是在app.js里面配置

 

 注意看我前面的kk,他后面的页面前部重新定位回到kk里面来

全部代码,很多没用的,关心router就好了

/**
 * 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');
import VueRouter from "vue-router";
Vue.use(VueRouter)

// 需要的就引入
import {Button,Input,Progress,Rate,Form,FormItem,Empty,Carousel,CarouselItem,Dialog,Backtop,Loading,} from 'element-ui';
const useArray=[Button,Input,Progress,Rate,Form,FormItem,Empty,Carousel,CarouselItem,Dialog,Backtop,Loading,]
import 'element-ui/lib/theme-chalk/input.css';
import 'element-ui/lib/theme-chalk/button.css';
import 'element-ui/lib/theme-chalk/icon.css';
import 'element-ui/lib/theme-chalk/progress.css';
import 'element-ui/lib/theme-chalk/rate.css';
import 'element-ui/lib/theme-chalk/form.css';
import 'element-ui/lib/theme-chalk/form-item.css';
import 'element-ui/lib/theme-chalk/empty.css';
import 'element-ui/lib/theme-chalk/carousel.css';
import 'element-ui/lib/theme-chalk/carousel-item.css';
import 'element-ui/lib/theme-chalk/dialog.css';
import 'element-ui/lib/theme-chalk/backtop.css';
import 'element-ui/lib/theme-chalk/loading.css';


import { Message, MessageBox } from 'element-ui'  //引入Message, MessageBox
import 'element-ui/lib/theme-chalk/message.css'
import 'element-ui/lib/theme-chalk/message-box.css'
Vue.prototype.$message = Message                //vue实例上挂载Message
Vue.prototype.$messagebox = MessageBox             //vue实例上挂载MessageBox







useArray.forEach((item)=>{
    Vue.use(item)
})
Vue.use(Loading.directive);  //  指令方式(v-loading)

// 加载动态效果,使用的插件
import VueLazyload from "vue-lazyload";
import loadingBars from './newHome/images/iconSvg/loading-bars.svg'
Vue.use(VueLazyload,{
    loading:loadingBars
})


// 倒计时组件
// https://github.com/fengyuanchen/vue-countdown/tree/v1
import VueCountdown from '@chenfengyuan/vue-countdown';
Vue.component(VueCountdown.name, VueCountdown);



// import {Button, Cell, CellGroup,Popup,Toast ,Checkbox, CheckboxGroup,Field ,Form  ,Picker ,Icon,RadioGroup, Radio ,Overlay ,Collapse, CollapseItem,ImagePreview,Lazyload ,Swipe, SwipeItem,IndexBar, IndexAnchor,Tab, Tabs ,Area   } from 'vant';
// const useArray = [Button, Cell, CellGroup,Popup,Toast ,Checkbox, CheckboxGroup,Field ,Form  ,Picker ,Icon,RadioGroup, Radio ,Overlay ,Collapse, CollapseItem,ImagePreview,Lazyload ,Swipe, SwipeItem,IndexBar, IndexAnchor,Tab, Tabs ,Area];
// useArray.forEach((item)=>{
//     Vue.use(item)
// })
/**
 * 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('.')[0], files(key).default))

// Vue.component('example-component', require('./components/ExampleComponent.vue').default);

// Vue配置路由,可能会对搜索引擎收录不太好
const routes = [
    {path:'/kk', name:'Home', component:()=>import('./newHome/pages/home.vue')},
    {path:'/kk/newSeckill', name:'Home', component:()=>import('./newHome/pages/SeckillPage.vue')},
    {path:'/kk/newCoupon', name:'Home', component:()=>import('./newHome/pages/CouponPage.vue')},
    {path:'/kk/newGroupPurchase', name:'Home', component:()=>import('./newHome/pages/GroupPurchasePage.vue')},
    {path:'/kk/newBrandZone', name:'Home', component:()=>import('./newHome/pages/BrandZonePage.vue')},
    {path:'/kk/newProduct', name:'Home', component:()=>import('./newHome/pages/NewProductPage.vue')},
]

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








//已经配置路由,下面这些多的话体积会越来越大,路由直接是页面切换
// Vue.component('home', require('./newHome/pages/home').default);
// Vue.component('seckill-page',require('./newHome/pages/SeckillPage').default);
// Vue.component('coupon-page',require('./newHome/pages/CouponPage').default);
// Vue.component('brand-zone-page',require('./newHome/pages/BrandZonePage').default);
// Vue.component('new-product-page',require('./newHome/pages/NewProductPage').default);
// Vue.component('group-purchase-page',require('./newHome/pages/GroupPurchasePage').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: router,
    el: '#app',
});

 

 

 

 

 

 

上面不太清除,就是你的路由里面

 

 

 

 

代码:

  Route::get('/kk{vue_capture?}','IndexController@newIndex')->where('vue_capture','[\/\w\.-]*');

 

 

 

 

 

参考网址:https://piethein.medium.com/how-to-combine-vuejs-router-with-laravel-1226acd73ab0

 

标签:laravel,Vue,component,element,vue,ui,import,路由
From: https://www.cnblogs.com/hechunfeng/p/16779775.html

相关文章

  • Vue项目中使用v-charts
    v-charts官网地址​​https://v-charts.js.org​​安装依赖打开命令行,输入vueui,打开可视化界面echarts依赖>安装依赖>运行依赖>echartsv-charts依赖>安装依赖>运行依赖>v......
  • vue-动态菜单 带本地动态路由结合
    思路:方法1.按照以往的动态菜单来做,就是根据权限调取后端接口,获取相应的菜单数据,对数据进行处理,添加到路由对象中方法2.自己在router.js中写全部的路由,然后设置一个标识,可......
  • v-debounce-throttle是一个vue防抖节流指令
    v-debounce-throttle是一个vue防抖节流指令简介v-debounce-throttle是一个vue防抖节流指令,控制单一事件的触发频率。其核心是拦截组件元素的v-on绑定事件,采用原生的事件......
  • vue-i18n 多语言安装依赖失败
    在vue2环境下,默认安装npminstallvue-i18n的版本是[email protected],所以报错信息如下:PSD:\myFile\dev\YSJ-dev\cbj-mall-manage>npmivue-i18n-savenpmERR!code......
  • 路由的配置和简单使用
     1、路由添加命令:pnpminstallvue-router@next--save  //@next表示最新 安装成功后dependencies里会出现路由的版本 "vue-router":"^4.0.13"如果项目正在......
  • Hbuilder运行Vue项目
    一.NodeJs的介绍二.NodeJs的安装与配置环境变量1.安装NodeJs官网:http://nodejs.cn/download/(注意:不要下载最新版本的NodeJs,会出现问题!)如果使用的是msi安装程序进行暗......
  • vue中is的作用和用法
    is的作用<ul><li></li><li></li><li></li></ul>总所周知,ul里面嵌套li的写法是html语法的固定写法(还有如table,select等)。//code1<ul><my-component></my-componen......
  • vue3中tab详情页多开keepalive根据key去动态缓存与清除缓存
    一.场景由于存在tab栏,当从查询页面点击列表进入详情时,需求是详情页都会新开一个tab,并缓存,tab中的切换不会重新加载详情页数据,但是关闭一个详情tab,再次从查询页点击这条详......
  • vue-router:history和hash的区别
    前言:写这个随笔是因为后端部署时,第一次进入页面无问题,刷新后页面空白,寻找原因发现有两个解决方案;1、后端nginx做保底映射,映射到正确的路径;2、前端更改为hash模式也可解决......
  • 如何运行别人的Vue项目
    1、将项目里的“node_modules”文件夹删除,一般“node_modules”文件夹太大,一般不会打包上传到svn、git上的,所以没有这个文件夹就不用删。2、删除package-lock.json。它是......