从代码中看,警告出现在formData2.categoryId这行代码上,警告的原因是formData2可能是未定义的。在LSTChildren方法中,formData2是一个reactive对象,但是在调用LSTChildren方法之前,并没有给formData2赋值,所以它是一个空对象。在第一个console.log之后,LSTChildren方法才开始执行,如果在第二个console.log中访问formData2,它可能还没有被赋值。所以,可以将第二个console.log移到then方法的回调函数中,确保在数据被赋值之后再访问formData2。修改后的代码如下:

const formData2 = reactive<CategoryForm>({});

function LSTChildren(categoryId?: string) {
    console.log("..开始执行LSTChildren方法..........");

    // 查的是自己(就是父级)
    getChildrenCategoryForm({ id: categoryId })
        .then(({ data }) => {
            data.forEach(item => {
                Object.assign(formData2, item);
                // console.log("..LSTChildren  完事儿了..?",formData2.categoryId);
            });
        })
        .finally(() => {
            loading.value = false;
            console.log("..LSTChildren  完事儿了.吗啊啊啊啊.formData2是是撒大大啊 ?", formData2.categoryId);
        });
}

/**
 * 打开资讯表单弹窗 【新增~修改 ById】
 *
 * @param categoryId
 */
function openDialog(categoryItem?: CategoryPageVO) {
    console.log('categoryItem是什么啊啊啊————————————————————————', categoryItem);
    LSTChildren(categoryItem.categoryId);
    dialog.visible = true;
    if (categoryItem) {
        dialog.title = "修改类目";
        loading.value = true;
        formData.categoryId = categoryItem.categoryId;
        formData.categoryName = categoryItem.categoryName;
        // formData.parentCategoryId = categoryItem.parentCategoryId;/////先查一个只有父id的接口

        // 然后父id的显示就是
        formData.parentCategoryId = formData2.categoryId;
        formData.categoryDesp = categoryItem.categoryDesp;
        formData.categoryIcon = categoryItem.categoryIcon;
        // formData.status = categoryItem.status;


        // formData.orderNum=categoryItem.orderNum;
        // formData.userId=categoryItem.userId;
        console.log('------------formData.parentCategoryId', formData.parentCategoryId);
        console.log('-----------parentCategoryId', categoryItem.parentCategoryId);
        // Object.assign(formData, categoryItem); ///表单
    } else {
        dialog.title = "新增类目";
        // formData.orderNum = 1;//lxh:新增第一条默认是最小值1  再增一条就是2 逐次递增  如果有两个1 那新增的第三条排序就显示2//再提交处新增

        console.log("---这是打开表单新增的openDialog新增---");
    }
}
const formData2 = reactiveCategoryForm;function LSTChildrencategoryId string consolelog开始执行LSTChildren方法; 查的是自己就是父级 getChildrenCategoryForm id categoryId then data = da

原文地址: https://www.cveoy.top/t/topic/i7dw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录