美文网首页
vue2-路由自动生成

vue2-路由自动生成

作者: coderfl | 来源:发表于2023-04-22 16:02 被阅读0次
// router.js
import Vue from "vue";
import VueRouter from "vue-router";
const files = require.context('../views', true, /\.vue$/)
const rs = []
files.keys().forEach(name => {
    const path = name.replaceAll('./', '/').replaceAll('.vue', '')
    console.log(path)
    rs.push({path: path, component: () => import(`../views${name.substr(1)}`)})
})
Vue.use(VueRouter)
export default new VueRouter({
    mode: 'history',
    routes: rs
})
image.png
image.png
image.png

相关文章

网友评论

      本文标题:vue2-路由自动生成

      本文链接:https://www.haomeiwen.com/subject/pebsjdtx.html