记录开发中的坑。。。

247 阅读1分钟

Vue

1 addRoutes

this.$router.options.routes

  • 使用addRoutesthis.$router.options.routes的数据没有发生变化
  • 手动更改
this.$router.options.routes = xxx
this.$router.addRoutes(xxx)

刷新页面 跳转路由为404

  • 在使用addRoutes添加路由时 404路由必须放在最后一个
{ path: '*', redirect: '/404'}

[vue-router] Duplicate named routes definition

  • 不同角色展现不同的路由时,提示警告有重复的名称
  • 使用addRoutes前,先重置路由
const createRouter = () => new Router({
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

2 elementui

table

  • 出现的问题
    • 点击编辑按钮,出现更改信息的弹窗
    • 数据是否更改,关闭弹窗,整行数据都发送奇怪变化
  • 使用scope.row,获取当前行的数据
<el-table-column label="操作">
  <template slot-scope="scope">
    <el-button
      size="mini"
      @click="edit(scope.row)"
    >编辑
    </el-button>
  </template>
</el-table-column>

edit(row){
    this.from = row
}
  • 解决
    • from对row的数据为引用传递,通过拷贝,解决问题
this.from  = JSON.parse(JSON.stringify(row))

form

当表单中使用v-if 使表单项在特定的条件下显示时,使用this.$refs[xxx].resetFields();重置验证,出现error

Cannot read property 'indexOf' of undefined
  • 解决
  • 使用v-show