动态路由权限时在 store 中读取不到 router 中的静态路由变量

在store 的 permission 中引入 router 中静态路由时值为undefined, 此时需要更改main.js中的引入顺序, 代码如下:

1
2
3
import store from './store'
import App from './App.vue'
import router from './router'

使用 element-ui 的表格多选时

给el-table标签添加:row-key以及@selection-change, 在第一列el-table-column标签中添加type="selection" :reserve-selection="true", 当然如果此时有过滤部分数据时可以添加selectable属性

selectable: 仅对 type=selection 的列有效, 类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选

reserve-selection: 仅对 type=selection 的列有效, 类型为 Boolean, 为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key)

在需要回显时, 通过返回的已选中数据在$nexTick中执行 table 的toggleRowSelection重新赋值一次table的:data 属性, 这样可以直接回显(即不会出现切换页面才会回显的 bug)

解决方案的 issue

element 的级联选择器(el-cascader)动态加载回显功能

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
props: {
  lazy: true,
  value: '', // 指定选项的值为选项对象的某个属性值
  label: '', // 指定选项标签为选项对象的某个属性值
  lazyLoad: (node, resolve) => {
    // 如果是编辑内容的时候
    if (this.$route.query.id) {
      if (!this.firstNode || !this.firstResolve) {
        if (node.level === 0) {
          this.firstNode = node
          this.firstResolve = resolve
        }
        return
      }
    }
    // 此处是异步请求的接口
    this.getSyncData(node, resolve)
  },
  leaf: '' // 是否还有下一级
},

...javascript
async created() {
  if (this.$route.query.id) {
    this.id = this.$route.query.id
    const res = await getXxxInfo(this.id)
    if (res.code === code) {
      this.getSyncData(this.firstNode, this.firstResolve)
    }
  }
},
methods: {
  async getSyncData(node, resolve) {
    const value = node.value || 0
    const res = await request(value)
    if (res.code === code) {
      resolve(res.data)
    }
  }
}

导出表格

  1. 后端返回流的形式
  2. 导出csv格式
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 导出csv
const tableToExcel = () => {
 // 要导出的json数据
 const jsonData = [
    {
      name:'路人甲',
      phone:'123456789',
      email:'000@123456.com'
    },
    {
      name:'炮灰乙',
      phone:'123456789',
      email:'000@123456.com'
    }
  ];
  // 列标题,逗号隔开,每一个逗号就是隔开一个单元格
  let str = `姓名,电话,邮箱
`;
  // 增加	为了不让表格显示科学计数法或者其他格式
  for(let i = 0 ; i < jsonData.length ; i++ ){
    for(const key in jsonData[i]){
      str+=`${jsonData[i][key] + '	'},`;    
    }
     str+='
';
  }
  // encodeURIComponent解决中文乱码
  const uri = 'data:text/csv;charset=utf-8,ufeff' + encodeURIComponent(str);
  // 通过创建a标签实现
  const link = document.createElement("a");
  link.href = uri;
  // 对下载的文件命名
  link.download =  "json数据表.csv";
  link.click();
}