cascader 动态加载级联数据

        <el-cascader v-model="filters.category_id" :clearable='true' :props="categoriesProp" :placeholder="filters.full_path" @change="onCategory" style="width: 300px"></el-cascader>

 categories: [],
      categoriesProp: {
        lazy: true,
        lazyLoad: this.handleCategory,
        emitPath: false
      },
     filters: {
        size: 20,
        page: 1,
        brand_id: '',
        order_by: '',
        order: '',
        search: '',
        category_id: '',
        full_path: '',
        tags: []
      },

 // Lazy load category
    handleCategory(node, resolve) {
      this.categoriesFilter.level = 1
      this.categoriesFilter.parent = node.value

      categoriesEnable(this.categoriesFilter).then(res => {
        if (res.data.code === 200) {
          const nodes = []
          for (const item of res.data.entries) {
            const option = {}
            option.label = item.name
            option.value = item.id
            option.parent = item.parent
            option.children = []
            option.leaf = item.is_leaf
            nodes.push(option)
          }
          resolve(nodes)
        }
      })
    },
    onCategory(e) {
      categoriesEnable(this.categoriesFilter).then(res => {
        if (res.data.code === 200) {
          for (const item of res.data.entries) {
            if (e === item.id) {
              this.filters.full_path = item.full_path
            }
          }
        }
      })
    },

版权声明:本文为sinat_36017053原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。