后台项目总结

 

一.动态路由的添加

  • 1.在首页请求权限菜单
 openMenu(item = {}) {
   this.$store.dispatch("GetMenu",{type: true,id: item.id}).then(data => {
       if (data.length !== 0) {
           this.$router.$avueRouter.formatRoutes(data, true);
       }
   });
 },
  • 2.动态添加路由
 const RouterPlugin = function() {
   this.$router = null
   this.$store = null
 }
 RouterPlugin.install = function(router, store) {
   this.$router = router
   this.$store = store
   function isURL(s) {
     return /^http[s]?:\/\/.*/.test(s)
   }
   function objToform(obj) {
     const result = []
     Object.keys(obj).forEach(ele => {
       result.push(`${ele}=${obj[ele]}`)
     })
     return result.join('&')
   }
   this.$router.$avueRouter = {
     // 全局配置
     

     $website: this.$store.getters.website,
     routerList: [],
     group: '',
     safe: this,
     // 设置标题
     setTitle: function(title) {
       title = title ? `${title}——${this.$website.title}` : this.$website.title
       document.title = title
     },
     closeTag: (value) => {
       const tag = value || this.$store.getters.tag
       this.$store.commit('DEL_TAG', tag)
     },
     // 处理路由
     getPath: function(params) {
       const { src } = params
       let result = src || '/'
       if (src.includes('http') || src.includes('https')) {
         result = `/myiframe/urlPath?${objToform(params)}`
       }
       return result
     },
     // 正则处理路由
     vaildPath: function(list, path) {
       let result = false
       list.forEach(ele => {
         if (new RegExp('^' + ele + '.*', 'g').test(path

相关文章:

  • 2022-12-23
  • 2021-07-20
  • 2022-03-08
  • 2022-03-06
  • 2022-12-23
  • 2021-08-11
  • 2021-12-28
  • 2021-07-10
猜你喜欢
  • 2022-02-07
  • 2021-05-17
  • 2022-02-10
  • 2021-08-04
  • 2021-10-28
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案